تابع ووکامرسی wc_update_product_stock تغییر و بروزرسانی تعداد موجودی کالا
تابع ووکامرسی wc_update_product_stock – تغییر و بروزرسانی تعداد موجودی کالا
Syntax – سینتکس
wc_update_product_stock( (int|WC_Product) $product, (constant) $stock_quantity = null, (string) $operation = 'set' );
Parameters – پارامتر ها (3)
- 1- $product (int|WC_Product)
- 2- $stock_quantity (constant)
- 3- $operation (string)
Usage – نحوه استفاده
if ( !function_exists( 'wc_update_product_stock' ) ) { require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-stock-functions.php'; } // The product. $product = null; // The stock quantity. $stock_quantity = null; // set, increase and decrease. $operation = 'set'; // NOTICE! Understand what this does before running. $result = wc_update_product_stock($product, $stock_quantity, $operation);
Defined – محل تعریف
/includes/wc-stock-functions.php
function wc_update_product_stock( $product, $stock_quantity = null, $operation = 'set' ) { if ( ! $product = wc_get_product( $product ) ) { return false; } if ( ! is_null( $stock_quantity ) && $product->managing_stock() ) { // Some products (variations) can have their stock managed by their parent. Get the correct ID to reduce here. $product_id_with_stock = $product->get_stock_managed_by_id(); $data_store = WC_Data_Store::load( 'product' ); $data_store->update_product_stock( $product_id_with_stock, $stock_quantity, $operation ); delete_transient( 'wc_low_stock_count' ); delete_transient( 'wc_outofstock_count' ); delete_transient( 'wc_product_children_' . ( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() ) ); wp_cache_delete( 'product-' . $product_id_with_stock, 'products' ); // Re-read product data after updating stock, then have stock status calculated and saved. $product_with_stock = wc_get_product( $product_id_with_stock ); $product_with_stock->set_stock_status(); $product_with_stock->save(); do_action( $product_with_stock->is_type( 'variation' ) ? 'woocommerce_variation_set_stock' : 'woocommerce_product_set_stock', $product_with_stock ); return $product_with_stock->get_stock_quantity(); } return $product->get_stock_quantity(); }
versions – نسخه ها
از نسخه : 3.0.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر