Ecommerce Shopify WordPress Discussion

On Backorders products assign automatic to new category

I'm trying to create a WordPress code when the products I have are on backorder to automatically import them as a primary backorder category. add_action('woocommerce_reduce_order_stock', 'update_stock_on_new_order', 10); function update_stock_on_new_order($order) { $status = $order->get_status(); if ($status == 'processing' || $status == 'completed' || $status == 'on-hold') { $items = $order->get_items(); foreach ($items as $item) { $product = $item->get_product(); if ($product->get_stock_status() != 'onbackorder') { //den kanei update to stock otan einai se katastasi proparaggelias $qty = $item->get_quantity(); $item_id = $item->get_id(); $product_id = $product->get_id(); $shop_stock = (int)get_post_meta($product_id, 'shop_stock', true); $supplier_stock = (int)get_post_meta($product_id, 'supplier_stock', true); if ($shop_stock == "") $shop_stock = 0; if ($supplier_stock == "") $supplier_stock = 0; if ($shop_stock > 0) { if ($shop_stock - $qty >= 0) { update_post_meta($product_id, 'shop_stock', $shop_stock - $qty); update_post_meta($item_id, 'shop_stock_item', $qty); update_post_meta($item_id, 'supplier_stock_item', 0); } else { update_post_meta($product_id, 'shop_stock', 0); $diff_stock = $qty - $shop_stock; update_post_meta($product_id, 'supplier_stock', $supplier_stock - $diff_stock); update_post_meta($item_id, 'shop_stock_item', $shop_stock); update_post_meta($item_id, 'supplier_stock_item', $diff_stock); } } elseif ($supplier_stock > 0) { update_post_meta($product_id, 'supplier_stock', $supplier_stock - $qty); update_post_meta($item_id, 'shop_stock_item', 0); update_post_meta($item_id, 'supplier_stock_item', $qty);
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.