wc_trigger_stock_change_actions()
Check if a product's stock quantity has reached certain thresholds and trigger appropriate actions.
This functionality was moved out of wc_trigger_stock_change_notifications in order to decouple it from orders, since stock quantity can also be updated in other ways.
Хуки из функции
Возвращает
null
. Ничего (null).
Использование
wc_trigger_stock_change_actions( $product );
- $product(WC_Product) (обязательный)
- The product whose stock level has changed.
Код wc_trigger_stock_change_actions() wc trigger stock change actions WC 9.3.3
function wc_trigger_stock_change_actions( $product ) { if ( true !== $product->get_manage_stock() ) { return; } $no_stock_amount = absint( get_option( 'woocommerce_notify_no_stock_amount', 0 ) ); $low_stock_amount = absint( wc_get_low_stock_amount( $product ) ); $stock_quantity = $product->get_stock_quantity(); if ( $stock_quantity <= $no_stock_amount ) { /** * Action fires when a product's stock quantity reaches the "no stock" threshold. * * @since 3.0 * * @param WC_Product $product The product whose stock quantity has changed. */ do_action( 'woocommerce_no_stock', $product ); } elseif ( $stock_quantity <= $low_stock_amount ) { /** * Action fires when a product's stock quantity reaches the "low stock" threshold. * * @since 3.0 * * @param WC_Product $product The product whose stock quantity has changed. */ do_action( 'woocommerce_low_stock', $product ); } }