Reputation: 33
I have a few custom order statuses that will automatically update from 'Pending Payment' to the applicable custom status when certain conditions are met.
The change in order status occurs automatically upon initial order creation in WooCommerce when an online purchase is completed.
Currently, the order status is correctly updated in WooCommerce however there is no reduction in inventory.
I followed suggestions from folks at stackoverflow and implemented the below code however it seems to have no effect.
add_action( 'woocommerce_order_status_amazon', 'wc_maybe_reduce_stock_levels' );
add_action( 'woocommerce_order_status_ebay', 'wc_maybe_reduce_stock_levels' );
});
and
/**
* @param array $statuses
* @return array
*/
function my_custom_woocommerce_order_is_paid_statuses( $statuses ) {
// already included statuses are processing and completed
$statuses[] = 'amazon';
$statuses[] = 'ebay';
return $statuses;
}
Can anyone identify what the issue may be? Thanks in advance.
Upvotes: 2
Views: 770
Reputation: 136
Maybe this will help:
add_action( 'woocommerce_order_status_changed', 'reduce_stock_amount', 20, 4 );
function reduce_stock_amount( $order_id, $old_status, $new_status, $order ){
if ( $new_status == 'amazon' || $new_status == 'ebay' ){
$stock_reduced = get_post_meta( $order_id, '_order_stock_reduced', true );
if( empty($stock_reduced) ){
wc_reduce_stock_levels($order_id);
}
}
}
Upvotes: 1