Last active
October 17, 2023 15:44
-
-
Save Matt-Welland/357efac95665b075aaeee5245839d9a2 to your computer and use it in GitHub Desktop.
Automatically change order status if specific product is found within order.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function custom_woocommerce_auto_complete_order( $order_id ) { | |
if ( ! $order_id ) { | |
return; | |
} | |
$order = wc_get_order( $order_id ); | |
$product_ids = array('12'); // Here set your targeted product(s) Id(s) | |
$product_found = true; | |
// Loop through order items | |
foreach ( $order->get_items() as $item ) { | |
if( ! array_intersect( $product_ids, array($item->get_product_id(), $item->get_variation_id()) ) ) { | |
$product_found = false; | |
break; | |
} | |
} | |
if( $order->has_status( 'processing' ) && $product_found ) { | |
$order->update_status( 'wc-arrival-shipment' ); | |
} | |
} | |
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment