从优惠券代码 WooCommerce 中检索优惠券详细信息
Retrieve coupon details from coupon code WooCommerce
我之前问过 however it does not answer the question of how to retrieve data from a coupon in WooCommerce. Both questions involve coupons, however, the 问的是如何设置元数据,这个问题问的是如何检索数据。
我正在尝试通过优惠券代码从 WooCommerce 获取优惠券的详细信息。但是,我不确定我应该如何尝试去做这件事。
我试过下面的代码。但是,它给了我错误 Call to undefined function WC_Coupon()
$coupon_code = 'save10percent';
global $woocommerce;
$c = WC_Coupon($coupon_code);
如何获取优惠券的详细信息?
我明白了。为了使 WC_Coupon
函数起作用,我需要在调用该函数之前添加 "new" 关键字。如下所示。
$coupon_code = 'save10percent';
global $woocommerce;
$c = new WC_Coupon($coupon_code);
现在我可以像这样获取优惠券的详细信息了
echo "Discount Amount ".$c->amount."<br>";//Get Discount amount
echo "Discount Type ".$c->discount_type."<br>";//Get type of discount
echo "Individual Use ".$c->individual_use."<br>";//Get individual use status
echo "Usage Count ".$c->usage_count."<br>";//Get number of times the coupon has been used
echo "Uage Limit ".$c->usage_limit."<br>";//Get usage limit
echo "Coupon Description ".$c->description."<br>";//Get coupon description
我之前问过
我正在尝试通过优惠券代码从 WooCommerce 获取优惠券的详细信息。但是,我不确定我应该如何尝试去做这件事。
我试过下面的代码。但是,它给了我错误 Call to undefined function WC_Coupon()
$coupon_code = 'save10percent';
global $woocommerce;
$c = WC_Coupon($coupon_code);
如何获取优惠券的详细信息?
我明白了。为了使 WC_Coupon
函数起作用,我需要在调用该函数之前添加 "new" 关键字。如下所示。
$coupon_code = 'save10percent';
global $woocommerce;
$c = new WC_Coupon($coupon_code);
现在我可以像这样获取优惠券的详细信息了
echo "Discount Amount ".$c->amount."<br>";//Get Discount amount
echo "Discount Type ".$c->discount_type."<br>";//Get type of discount
echo "Individual Use ".$c->individual_use."<br>";//Get individual use status
echo "Usage Count ".$c->usage_count."<br>";//Get number of times the coupon has been used
echo "Uage Limit ".$c->usage_limit."<br>";//Get usage limit
echo "Coupon Description ".$c->description."<br>";//Get coupon description