wc_trigger_stock_change_notifications()
After stock change events, triggers emails and adds order notes.
Возвращает
null
. Ничего (null).
Использование
wc_trigger_stock_change_notifications( $order, $changes );
- $order(WC_Order) (обязательный)
- order object.
- $changes(массив) (обязательный)
- Array of changes.
Список изменений
С версии 3.5.0 | Введена. |
Код wc_trigger_stock_change_notifications() wc trigger stock change notifications WC 9.4.2
function wc_trigger_stock_change_notifications( $order, $changes ) { if ( empty( $changes ) ) { return; } $order_notes = array(); $no_stock_amount = absint( get_option( 'woocommerce_notify_no_stock_amount', 0 ) ); foreach ( $changes as $change ) { $order_notes[] = $change['product']->get_formatted_name() . ' ' . $change['from'] . '→' . $change['to']; $low_stock_amount = absint( wc_get_low_stock_amount( wc_get_product( $change['product']->get_id() ) ) ); if ( $change['to'] <= $no_stock_amount ) { /** * Action to signal that the value of 'stock_quantity' for a variation is about to change. * * @since 4.9 * * @param int $product The variation whose stock is about to change. */ do_action( 'woocommerce_no_stock', wc_get_product( $change['product']->get_id() ) ); } elseif ( $change['to'] <= $low_stock_amount ) { /** * Action to signal that the value of 'stock_quantity' for a product is about to change. * * @since 4.9 * * @param int $product The product whose stock is about to change. */ do_action( 'woocommerce_low_stock', wc_get_product( $change['product']->get_id() ) ); } if ( $change['to'] < 0 ) { /** * Action fires when an item in an order is backordered. * * @since 3.0 * * @param array $args { * @type WC_Product $product The product that is on backorder. * @type int $order_id The ID of the order. * @type int|float $quantity The amount of product on backorder. * } */ do_action( 'woocommerce_product_on_backorder', array( 'product' => wc_get_product( $change['product']->get_id() ), 'order_id' => $order->get_id(), 'quantity' => abs( $change['from'] - $change['to'] ), ) ); } } $order->add_order_note( __( 'Stock levels reduced:', 'woocommerce' ) . ' ' . implode( ', ', $order_notes ) ); }