Automattic\WooCommerce\Internal\PushNotifications\Triggers

StockNotificationRecoveryHandler::on_stock_changepublicWC 10.9.0

Evaluates each event subtype's recovery threshold and clears the corresponding sent-meta when the new stock level has recovered.

Метод класса: StockNotificationRecoveryHandler{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$StockNotificationRecoveryHandler = new StockNotificationRecoveryHandler();
$StockNotificationRecoveryHandler->on_stock_change( $product ): void;
$product(WC_Product) (обязательный)
The product whose stock changed.

Список изменений

С версии 10.9.0 Введена.

Код StockNotificationRecoveryHandler::on_stock_change() WC 10.9.1

public function on_stock_change( WC_Product $product ): void {
	$product_id = $product->get_id();

	if ( $product_id <= 0 ) {
		return;
	}

	$stock_quantity = $product->get_stock_quantity();

	if ( null === $stock_quantity ) {
		return;
	}

	$stock = (int) $stock_quantity;

	if ( $stock > (int) wc_get_low_stock_amount( $product ) ) {
		$this->clear_meta( $product_id, StockNotification::EVENT_LOW_STOCK );
	}

	if ( $stock > (int) get_option( 'woocommerce_notify_no_stock_amount', 0 ) ) {
		$this->clear_meta( $product_id, StockNotification::EVENT_OUT_OF_STOCK );
	}

	if ( $stock >= 0 ) {
		$this->clear_meta( $product_id, StockNotification::EVENT_ON_BACKORDER );
	}
}