• Resolved TechPik

    (@techpik)


    How do I create a rule that does not change the status of recurring customer orders? Currently, I have made a rule which changes order statuses from Processing to Complete. This works nicely, but I notice that some customers order multiple (identified by same billing email address) times and I don’t want to change those orders to Completed.

    • This topic was modified 2 years, 3 months ago by TechPik.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter TechPik

    (@techpik)

    Any help?

    Hello @techpik,

    Sorry for the late reply.

    We’re sorry to let you know that, as of right now, using our plugin, it is not possible to prevent a recurring customer’s order from having its order status changed. However, I have passed your request on to our development team. They will check the viability of this and get back to you as soon as they can.

    Kind regards,
    Moshtafizur

    Thread Starter TechPik

    (@techpik)

    Thank you very much. It would be very helpful feature.

    Plugin Author Algoritmika

    (@algoritmika)

    Hi @techpik,

    If you are ok with adding a small PHP snippet to your site, this should solve your task:

    add_filter( 'alg_wc_order_status_rules_do_apply_rule', function ( $do_apply, $order, $rule_id, $args ) {
        if ( $do_apply ) {
            $orders = wc_get_orders( array( 'billing_email' => $order->get_billing_email(), 'exclude' => array( $order->get_id() ), 'limit' => 1, 'return' => 'ids' ) );
            if ( count( $orders ) > 0 ) {
                return false;
            }
        }
        return $do_apply;
    }, 10, 4 );

    Please let me know what you think.

    Thread Starter TechPik

    (@techpik)

    Thank you, its working perfectly. Thank you.

    • This reply was modified 2 years, 2 months ago by TechPik.
    Plugin Author Algoritmika

    (@algoritmika)

    Hi @techpik,

    Happy to hear it’s solved ?? Let me know if you need anything else.

    And if you like the plugin, please consider leaving me a rating.

    Thread Starter TechPik

    (@techpik)

    Thanks for the code, it works nice, but could it be that it is using a lot of CPU? I received the following message from the host (see below). Is it possible that I have too many orders that it needs to process? Can the code be made to check recurring emails from orders that are at most 1 month old?

    Website host recorded almost 300 slow SQL queries for the last 24 hours. All of them are SELECT SQL queries and they looks like the one below:

    Executed 6h 47m 18s ago for 6.566684 sec on Database –> dbk9jpzqg6gvbh
    Date: 2023-01-04 06:32:34 Query_time: 6.566684 Rows_examined: 2499816: Rows_sent 1 Lock_time: 0.000330 Query_chars: 425
    SELECT COUNT(DISTINCT posts.ID) as total_guest_orders FROM wpdy_posts AS posts INNER JOIN wpdy_postmeta AS postmeta ON postmeta.post_id = posts.ID INNER JOIN wpdy_postmeta AS billing_email ON billing_email.post_id = posts.ID WHERE posts.post_type = ‘shop_order’ AND postmeta.meta_key = ‘_customer_user’ AND postmeta.meta_value = 0 AND billing_email.meta_value IN(‘mica**@liv*.pt’);

    Thread Starter TechPik

    (@techpik)

    Do you know how to solve the CPU problem or do you know where can I find freelancer to do it?

    Hi @techpik,

    Sorry for the late reply regarding the issue.

    I have escalated this with our development team. They will get back to you as soon as they can.

    Kind regards,
    Moshtafizur

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @techpik,

    To limit it to one month old orders only, you need to replace this line in our snippet:

    $orders = wc_get_orders( array( 'billing_email' => $order->get_billing_email(), 'exclude' => array( $order->get_id() ), 'limit' => 1, 'return' => 'ids' ) );

    with this one:

    $orders = wc_get_orders( array( 'billing_email' => $order->get_billing_email(), 'exclude' => array( $order->get_id() ), 'limit' => 1, 'return' => 'ids', 'date_created' => '>' . ( time() - MONTH_IN_SECONDS ) ) );

    That is, we’ve added:

    'date_created' => '>' . ( time() - MONTH_IN_SECONDS )

    As you can see, I’ve used date_created, however, you can also use other dates, e.g., date_completed (you can read more here).

    Please give it a try and let me know what you think.

    • This reply was modified 2 years, 1 month ago by Algoritmika.
    • This reply was modified 2 years, 1 month ago by Algoritmika.
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Rule for recurring customers’ is closed to new replies.