Woocommerce DISABLE autocomplete € 0 orders - wordpress

I wish i could just use Uncle Google but he serve me only what i DON'T want :D
I have a free Product on my website. But I want to check every order manualy, because it's only for company accounts and not for "customers".
But every order will set the Status to approved - or what ever in english language- and the order is complete.
The user has automaticaly acces to "restricted area" and that's what I don't want. I want to check every order manualy and pick every spam account.
I can imagine, this is going to work with only one simple function but I can't get it. It's only one free Product, other Products are for moneeeeey.
It would be great if somebody has the same issue and can help me :)
Thank you

Place the following function in your active theme functions.php. Check all default statuses here and change on-hold to what you want - https://woocommerce.wp-a2z.org/oik_api/wc_get_order_statuses/
function change_free_order_status( $order_id ) {
if ( ! $order_id ) {return;}
$order = wc_get_order( $order_id );
if($order->get_total() <= 0):
$order->update_status( 'on-hold' ); // Change to what you need
endif;
}
add_action('woocommerce_thankyou','change_free_order_status');

Related

Set Woocommerce new orders to "On hold" and send "on hold" email [duplicate]

This question already has answers here:
Change COD default order status to "On Hold" instead of "Processing" in Woocommerce
(3 answers)
Change default WooCommerce order status to processing for cheque and bacs payments
(2 answers)
Closed last year.
I would like to ask.
Is there any way I can automatically make every new Woocommerce order’s status on hold?
Paypal and Visa card payments is getting automatically “processing” status but I don’t want that. I would like all my new orders getting order status “On Hold” and getting on hold email
I have found the following code which I add it on function child theme and is working fine but there is a small problem.
The customer still getting proccessing status email instead of getting “On hold” email.
/**
* Auto On hold all WooCommerce orders.
*/
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
if( 'processing'== $order->get_status() ) {
$order->update_status( 'on-hold' );
}
}
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
Is there anyway that I can edit this code and customer get the “On hold” email instead of processing email?
Please let me know if someone can help me.
Thank You!

How to count only active users as referred users?

I am using self-hosted WordPress. And, I need a refer system for my site. It's a membership type site.
Where I offer refer code to some specific members. So, they can refer others.
And, when someone sign ups through their refer link, they will get a point.
For referral code, I am using WP Referral Code (https://wordpress.org/plugins/wp-referral-code/).
And, for membership I am using Ultimate Member Plugin!
But the issue is, WP Referral Code is counting registrations when someone hit the sign up button!
Even If I reject he membership via Ultimate Plugin, its still being counted!
How can i count only valid signups which are active right now? Not all sign ups, just manually approved sign ups.
update WP Referral Code to new version and paste this in your functions.php file
add_filter( 'wp_referral_code_validate_submission', function ($result){
return false;
}, 1, 1);
add_action( 'wp_referral_code_before_refer_submitted', function ( $new_user_id, $referrer_user_id){
update_user_meta( $new_user_id, 'shalior_referrer_id', $referrer_user_id);
} , 10 , 2);
add_action( 'um_after_user_is_approved', 'shalior_um_after_user_is_approved', 10, 1 );
function shalior_um_after_user_is_approved( $user_id ) {
$referrer_user_id = get_user_meta( $user_id, 'shalior_referrer_id', true);
update_user_meta( $user_id, 'wrc_referrer_id', $referrer_user_id );
wp_referral_code_add_user_to_referrer_invite_list($user_id , $referrer_user_id);
}

WooCommerce woocommerce_new_order not firing when creating an order from the REST API

I have the following code snippet:
add_action('woocommerce_new_order', 'foo_function', 10);
If I create a new order from the admin panel, this fires just fine.
However, creating it via the REST API will not fire the function.
Why is that?
Update
I've tried using the following:
woocommerce_rest_insert_shop_object – this one doesn't fire at all.
wp_insert_post and save_post – they do fire, but don't contain the line items... (on the first run, it's an empty list, and on the second run (where the $update flag is true) there is an item but that item has no data (like product id or quantity).
add_action( "woocommerce_rest_insert_shop_order_object", 'your_prefix_on_insert_rest_api', 10, 3 );
function your_prefix_on_insert_rest_api( $object, $request, $is_creating ) {
if ( ! $is_creating ) {
return;
}
$order_id = $object->get_id();
$wc_order = new WC_Order( $order_id );
do_action( 'woocommerce_new_order', $order_id, $wc_order );
}
You have tried woocommerce_rest_insert_shop_object,
but the hook is woocommerce_rest_insert_shop_order_object
Please use this hook woocommerce_process_shop_order_meta instead of woocommerce_new_order As far as I can determine, woocommerce_new_order is only fired when an order is processed through the checkout. In a lot of instances, staff were creating orders in the wp-admin and assigning them straight to processing or completed, which meant that hook wasn't doing what I thought it would. Using woocommerce_process_shop_order_meta will solve it for you.
On v2 there is the woocommerce_rest_insert_{$this->post_type}_object filter
So the correct hook for what you need is woocommerce_rest_insert_shop_order_object

How to get Pay Now URL with custom order status in WooCommerce?

I want to get the URL from where the customer can directly pay for their Invoice and also it should work with wc-cancelled and wc-transaction-declined (custom order status).
My Solution
What I'm doing now is created a custom page with my custom get parameters and processing the whole Payment Process as Documentation in Gateway provider Website.
My Problem
But the problem is whenever they update their doc file and plugin I also have to update my code; but if I get the Pay Now URL then WooCommerce and Gateway Plugin will take care of it.
Is there a better solution?
I got the solution in WooCommerce templates/emails/customer-invoice.php file. The function that I was looking for is get_checkout_payment_url().
Usage
$order = wc_get_order($order_id);
$pay_now_url = esc_url( $order->get_checkout_payment_url() );
echo $pay_now_url; //http://example.com/checkout/order-pay/{order_id}?pay_for_order=true&key={order_key}
//http://example.com will be site_url and protocol will depending upon SSL checkout WooCommerce setting.
But this url only works with pending, failed order status; So I used filter woocommerce_valid_order_statuses_for_payment
if (!function_exists('filter_woocommerce_valid_order_statuses_for_payment')) {
//http://woocommerce.wp-a2z.org/oik_api/wc_abstract_orderneeds_payment/
//http://hookr.io/filters/woocommerce_valid_order_statuses_for_payment/
// define the woocommerce_valid_order_statuses_for_payment callback 
function filter_woocommerce_valid_order_statuses_for_payment( $array, $instance ) {
$my_order_status = array('cancelled', 'transaction-declined');
return array_merge($array, $my_order_status);
}
// add the filter 
add_filter('woocommerce_valid_order_statuses_for_payment', 'filter_woocommerce_valid_order_statuses_for_payment', 10, 2);
}
^^ I added this in my active theme's functions.php file.
Reference:
get_checkout_payment_url()
wc_abstract_orderneeds_payment
woocommerce_valid_order_statuses_for_payment
You can get url with below code but it will work for wc-pending status order only, with the help of order_id or post_id
$order = wc_get_order($order_id);
echo $pay_now_url = $order->get_checkout_payment_url();

Wordpress: Change user role conditionally

I am creating a Wordpress website for multi author and want to set user role as per article submission. Means if any user have 0-10 article they will go to Contributor role, if 11-30 will go to Author role if 31-100 will go to Editor role.
Also I want to make registration system where default registration group will be Subscriber. They will get a link into verification email like
If you want to become a Contributor please click on below link. (To submit an article you must have at least Contributor permission)
http:// link will be here ... this link automatically change user role from Subscriber to Contributor.
Hope I will get solution from you expert. I am posting this issue with lots of hope from you friends.
What you want to do is when they post their submission check to see how many posts they have authored and then change the role. So in your theme's functions.php file you'd need a hook that is like this.
add_action('publish_post', 'update_roles');
and then a function to update the roles.
function update_roles()
{
global $wpdb;
// Get the author
$author = wp_get_current_user();
// Not sure if $author and $u are the same object I suspect they are.
// so this may not be necessary, but I found this code elsewhere.
// You may be able to do without this and just replace $u with $author later in the code.
// Get post by author
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_author = " . $author->ID );
$numPost = count($posts);
// Do the checks to see if they have the roles and if not update them.
if($numPost > 0 && $numposts <= 10 && current_user_can('subscriber'))
{
// Remove role
$author->remove_role( 'subscriber' );
// Add role
$author->add_role( 'contributor' );
}
...... other conditions .......
}
Using SQL statements (Database Queries) to get at Wordpress data is not in accordance with Wordpress coding standards . See Wordpress Handbook
It would be better to use count_user_posts function
See Function on the codex

Resources