Skip to content

Instantly share code, notes, and snippets.

@Matt-Welland
Last active October 17, 2023 15:44
Show Gist options
  • Save Matt-Welland/357efac95665b075aaeee5245839d9a2 to your computer and use it in GitHub Desktop.
Save Matt-Welland/357efac95665b075aaeee5245839d9a2 to your computer and use it in GitHub Desktop.
Automatically change order status if specific product is found within order.
<?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