A few weeks ago, I created little hook that autocompletes orders when they consist of a particular category of product.

/**
 * Autocomplete orders with only an 'abo' product
 */

add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) { 
if ( ! $order_id ) {
    return;
}

$order = wc_get_order( $order_id );
    // just in case

    $items = $order->get_items();

    foreach ( $items as $item ) {
        $product = $order->get_product_from_item( $item );

        // check if there's an "abo" in the order, then if there's anything else.
        if ( has_term( 'abo', 'product_cat', $product->id ) ) {
            $abo_in_order = 'true';
        }
        if ( has_term( 'goodies', 'product_cat', $product->id ) || has_term( 'revue', 'product_cat', $product->id ) || has_term( 'livre', 'product_cat', $product->id ) ) {
            $abo_alone_in_order = 'false';
        }
        else {
            $abo_alone_in_order = 'true';
        }
    }
    // if there's an 'abo' and nothing else, change the e-mail recipient to dada@sotiaf.fr
    if ( ($abo_in_order == 'true')&&($abo_alone_in_order == 'true') ) {
        $order->update_status( 'completed' );
    }
}

It used to work but hasn’t for a few days, perhaps after a WooCommerce update. The whole ‘has_term’ part works fine as it is used in another function hooked to ‘woocommerce_email_recipient_new_order’, it seems the problem comes either from the thankyou hook or from the update_status action.

Does that make sense to anyone ?

Thanks,
Joss

Read more here: Function hooked to ‘woocommerce_thankyou’ has stopped working


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: