WC_Discounts::validate_coupon_excluded_product_ids()protectedWC 3.2.0

Exclude products.

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

Хуков нет.

Возвращает

true|false.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->validate_coupon_excluded_product_ids( $coupon );
$coupon(WC_Coupon) (обязательный)
Coupon data.

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

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

Код WC_Discounts::validate_coupon_excluded_product_ids() WC 8.7.0

protected function validate_coupon_excluded_product_ids( $coupon ) {
	// Exclude Products.
	if ( count( $coupon->get_excluded_product_ids() ) > 0 ) {
		$products = array();

		foreach ( $this->get_items_to_validate() as $item ) {
			if ( $item->product && in_array( $item->product->get_id(), $coupon->get_excluded_product_ids(), true ) || in_array( $item->product->get_parent_id(), $coupon->get_excluded_product_ids(), true ) ) {
				$products[] = $item->product->get_name();
			}
		}

		if ( ! empty( $products ) ) {
			/* translators: %s: products list */
			throw new Exception( sprintf( __( 'Sorry, this coupon is not applicable to the products: %s.', 'woocommerce' ), implode( ', ', $products ) ), 113 );
		}
	}

	return true;
}