WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_Discounts::is_coupon_valid() public WC 3.2.0

Check if a coupon is valid.

Error Codes:

  • 100: Invalid filtered.
  • 101: Invalid removed.
  • 102: Not yours removed.
  • 103: Already applied.
  • 104: Individual use only.
  • 105: Not exists.
  • 106: Usage limit reached.
  • 107: Expired.
  • 108: Minimum spend limit not met.
  • 109: Not applicable.
  • 110: Not valid for sale items.
  • 111: Missing coupon code.
  • 112: Maximum spend limit met.
  • 113: Excluded products.
  • 114: Excluded categories.

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

Возвращает

true|false|WP_Error.

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

$WC_Discounts = new WC_Discounts();
$WC_Discounts->is_coupon_valid( $coupon );
$coupon(WC_Coupon) (обязательный)
Coupon data.

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

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

Код WC_Discounts::is_coupon_valid() WC 5.6.0

public function is_coupon_valid( $coupon ) {
	try {
		$this->validate_coupon_exists( $coupon );
		$this->validate_coupon_usage_limit( $coupon );
		$this->validate_coupon_user_usage_limit( $coupon );
		$this->validate_coupon_expiry_date( $coupon );
		$this->validate_coupon_minimum_amount( $coupon );
		$this->validate_coupon_maximum_amount( $coupon );
		$this->validate_coupon_product_ids( $coupon );
		$this->validate_coupon_product_categories( $coupon );
		$this->validate_coupon_excluded_items( $coupon );
		$this->validate_coupon_eligible_items( $coupon );

		if ( ! apply_filters( 'woocommerce_coupon_is_valid', true, $coupon, $this ) ) {
			throw new Exception( __( 'Coupon is not valid.', 'woocommerce' ), 100 );
		}
	} catch ( Exception $e ) {
		/**
		 * Filter the coupon error message.
		 *
		 * @param string    $error_message Error message.
		 * @param int       $error_code    Error code.
		 * @param WC_Coupon $coupon        Coupon data.
		 */
		$message = apply_filters( 'woocommerce_coupon_error', is_numeric( $e->getMessage() ) ? $coupon->get_coupon_error( $e->getMessage() ) : $e->getMessage(), $e->getCode(), $coupon );

		return new WP_Error(
			'invalid_coupon',
			$message,
			array(
				'status' => 400,
			)
		);
	}
	return true;
}