Skip to content

Instantly share code, notes, and snippets.

@NickGreen
Created November 15, 2017 21:32
Show Gist options
  • Save NickGreen/f9b38873547ff969c900e8407245d094 to your computer and use it in GitHub Desktop.
Save NickGreen/f9b38873547ff969c900e8407245d094 to your computer and use it in GitHub Desktop.
Autocomplete orders for a specific product in WooCommerce
<?php
/**
* Auto Complete all WooCommerce orders of a specific 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 );
foreach ( $order->get_items() as $item_id => $item_values ) {
$product_id = $item_values->get_product_id();
if ( $product_id == 326 ) {
$order->update_status( 'completed' );
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment