• Resolved okoo

    (@okoo)


    Hi there!
    I find your plugin very helpful! But I would like to ask you if you could add a function. Let me explain:

    I use WooCommerce to let user book events. I would like to update the status of the order the day after the event has been made.
    Basically I have an ACF on my product page where I set the date of the event and it would be great if your plugin could check the ACF’s date and update the status after that date.

    Do you think would be possible?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Algoritmika

    (@algoritmika)

    Hi @okoo,

    I believe this is doable. We would need to add a PHP snippet to your site though. If that’s ok – there is the alg_wc_order_status_rules_do_apply_rule filter in our plugin. It allows you to customize the conditions of when the rule should be applied. So you need to add a simple rule, e.g.: Rule #1 / Status from: Processing / Status to: Completed. Set the “Time trigger” option to 0 (we will override that with our snippet). And finally, add this snippet to your site:

    add_filter( 'alg_wc_order_status_rules_do_apply_rule', function( $do_apply, $order, $rule_id, $args ) {
        if ( 1 == $rule_id && $do_apply ) {
            $date_to_check = '2022-06-01'; // TODO: get the date of the event from the ACF here
            return ( time() >= strtotime( $date_to_check ) );
        }
        return $do_apply;
    }, 10, 4 );

    The only thing I’m not sure about is how to get the date of the event from the ACF. As you can see, in my snippet I’ve simply put 2022-06-01. Could you please give me more info so I could come up with an exact code? E.g. is this date stored in product meta? If so, what’s the meta key?

    Thread Starter okoo

    (@okoo)

    Hi there! Thanks for your quick answer!

    I’ve made a check, hope that my answer could help, otherwise feel free to ask me and I will try to provide more info ??

    So, I’ve created a test product with a date for the event (02 July 20249. In DB I’ll get this value into “_postmeta” table with:

    post_id: the ID of the product

    meta_key: data-evento (this is the name of the ACF field i’ve created with field type “date picker”)

    with this meta_value: 20240702

    Hope to have provided you the right info! ??

    Plugin Author Algoritmika

    (@algoritmika)

    Hi @okoo,

    Ok, so I think this snippet should solve it:

    add_filter( 'alg_wc_order_status_rules_do_apply_rule', function( $do_apply, $order, $rule_id, $args ) {
        if ( 1 == $rule_id && $do_apply ) {
            $date_to_check = false;
            foreach ( $order->get_items() as $item ) {
                $product_id = ( ! empty( $item['variation_id'] ) ? $item['variation_id'] : $item['product_id'] );
                if ( ( $date_to_check = get_post_meta( $product_id, 'data-evento', true ) ) ) {
                    break;
                }
            }
            return ( $date_to_check && time() >= strtotime( $date_to_check ) );
        }
        return $do_apply;
    }, 10, 4 );

    Please note that if your order has multiple products, the snippet will take the date of the first product with a non-empty data-evento meta.

    Please give it a try and let me know if that works.

    Thread Starter okoo

    (@okoo)

    Thank you so much for your help!
    I’ve tested it right now and it seems to work perfectly!

    I really appreciate your precious help!

    Plugin Author Algoritmika

    (@algoritmika)

    Hi @okoo,

    Happy to help ?? Let me know if you’ll need anything else.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Idea for improvement’ is closed to new replies.