Automattic\WooCommerce\Api\Queries\Coupons
GetCoupon::execute
Retrieve a coupon by ID or code.
Метод класса: GetCoupon{}
Хуков нет.
Возвращает
?Coupon.
Использование
$GetCoupon = new GetCoupon(); $GetCoupon->execute( #[Description( foo )] ?int $id, #[Description( fooo )] ?string $code, ): ?Coupon;
[Description( foo )] ?int $id
: .
По умолчанию: null
[Description( fooo )] ?string $code
: .
По умолчанию: null
- (обязательный)
- .
Код GetCoupon::execute() GetCoupon::execute WC 11.0.1
public function execute(
#[Description( 'The ID of the coupon to retrieve.' )]
?int $id = null,
#[Description( 'The coupon code to look up.' )]
?string $code = null,
): ?Coupon {
if ( ( null === $id ) === ( null === $code ) ) {
throw new \InvalidArgumentException( 'Exactly one of "id" or "code" must be provided.' );
}
$wc_coupon = new \WC_Coupon( $id ?? $code );
if ( ! $wc_coupon->get_id() ) {
return null;
}
return CouponMapper::from_wc_coupon( $wc_coupon );
}