تابع ووکامرسی wc_reduce_stock_levels کاهش موجودی محصول بر اساس سفارش
تابع ووکامرسی wc_reduce_stock_levels – کاهش موجودی محصول بر اساس سفارش
Syntax – سینتکس
wc_reduce_stock_levels( (int|WC_Order) $order_id );
Parameters – پارامتر ها (1)
- 1- $order_id (int|WC_Order)
Usage – نحوه استفاده
if ( !function_exists( 'wc_reduce_stock_levels' ) ) { require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-stock-functions.php'; } // The order id. $order_id = null; // NOTICE! Understand what this does before running. $result = wc_reduce_stock_levels($order_id);
Defined – محل تعریف
/includes/wc-stock-functions.php
function wc_reduce_stock_levels( $order_id ) { if ( is_a( $order_id, 'WC_Order' ) ) { $order = $order_id; $order_id = $order->get_id(); } else { $order = wc_get_order( $order_id ); } if ( 'yes' === get_option( 'woocommerce_manage_stock' ) && $order && apply_filters( 'woocommerce_can_reduce_order_stock', true, $order ) && sizeof( $order->get_items() ) > 0 ) { foreach ( $order->get_items() as $item ) { if ( $item->is_type( 'line_item' ) && ( $product = $item->get_product() ) && $product->managing_stock() ) { $qty = apply_filters( 'woocommerce_order_item_quantity', $item->get_quantity(), $order, $item ); $item_name = $product->get_formatted_name(); $new_stock = wc_update_product_stock( $product, $qty, 'decrease' ); if ( ! is_wp_error( $new_stock ) ) { /** translators: 1: item name 2: old stock quantity 3: new stock quantity */ $order->add_order_note( sprintf( __( '%1$s stock reduced from %2$s to %3$s.', woocommerce ), $item_name, $new_stock + $qty, $new_stock ) ); // Get the latest product data. $product = wc_get_product( $product->get_id() ); if ( '' !== get_option( 'woocommerce_notify_no_stock_amount' ) && $new_stock <= get_option( 'woocommerce_notify_no_stock_amount' ) ) { do_action( 'woocommerce_no_stock', $product ); } elseif ( '' !== get_option( 'woocommerce_notify_low_stock_amount' ) && $new_stock <= get_option( 'woocommerce_notify_low_stock_amount' ) ) { do_action( 'woocommerce_low_stock', $product ); } if ( $new_stock < 0 ) { do_action( 'woocommerce_product_on_backorder', array( 'product' => $product, 'order_id' => $order_id, 'quantity' => $qty ) ); } } } } // ensure stock is marked as "reduced" in case payment complete or other stock actions are called $order->get_data_store()->set_stock_reduced( $order_id, true ); do_action( 'woocommerce_reduce_order_stock', $order ); } }
versions – نسخه ها
از نسخه : 3.0.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر