How to re save all variations of a variable product when a WooCommerce order is paid?

Rate this post

I use following code to re save the product variations, when there is a paid order on it, but nothing happen

add_action('woocommerce_payment_complete', 'refresh_zero_stock');
function refresh_zero_stock($order_id){
    $order = new WC_Order( $order_id );
    foreach ($order->get_items() as $item_key => $item ){
        $item_quantity  = $item->get_quantity();
        if($item_quantity == 0){
            $product_id   = $item->get_product_id();
            $product_data = wc_get_product($product_id);
            if ($product_data->is_type('variable')){
                $handle = new WC_Product_Variable($product_id);
                foreach ($variations1 as $value) {
                    $single_variation=new WC_Product_Variation($value);

what is the problem with this action hook? please help.



I find the problem. I have to add




Leave a Reply

Your email address will not be published.

Back to top button