Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save renancmfreitas/26bc49cacb00ba03288b10dba81b0a06 to your computer and use it in GitHub Desktop.
Save renancmfreitas/26bc49cacb00ba03288b10dba81b0a06 to your computer and use it in GitHub Desktop.
/**
* Auto reduce WooCommerce order stock at checkout.
* Add to theme functions.php file
*/
add_action( 'woocommerce_thankyou', 'woocommerce_reduce_order_stock' );
function woocommerce_reduce_order_stock( $order_id ) {
global $woocommerce;
if ( !$order_id )
return;
$order = new WC_Order( $order_id );
$order->reduce_order_stock();
}
add_filter( 'woocommerce_payment_complete_reduce_order_stock', '__return_false' ); /** reduce stock just once */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment