WC_Discounts::validate_coupon_exists()protectedWC 3.2.0

Ensure coupon exists or throw exception.

A coupon is also considered to no longer exist if it has been placed in the trash, even if the trash has not yet been emptied.

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

Хуков нет.

Возвращает

true|false.

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

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

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

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

Код WC_Discounts::validate_coupon_exists() WC 8.7.0

protected function validate_coupon_exists( $coupon ) {
	if ( ( ! $coupon->get_id() && ! $coupon->get_virtual() ) || 'trash' === $coupon->get_status() ) {
		/* translators: %s: coupon code */
		throw new Exception( sprintf( __( 'Coupon "%s" does not exist!', 'woocommerce' ), esc_html( $coupon->get_code() ) ), 105 );
	}

	return true;
}