我以前曾问过this question,但是它没有回答如何从WooCommerce的优惠券中检索数据的问题。这两个问题都涉及优惠券,然而,first question在问如何设置元数据,这个问题询问如何检索数据。
我试图通过优惠券代码从WooCommerce获得优惠券的详细信息。然而,我不知道我应该如何努力这样做。
我已经试过下面的代码了。但是,它给出了错误Call to undefined function WC_Coupon()。
$coupon_code = 'save10percent';
global $woocommerce;
$c = WC_Coupon($coupon_code);人们应该如何去获取优惠券的细节?
发布于 2017-11-27 17:56:15
我想通了。为了使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 descriptionhttps://stackoverflow.com/questions/47517058
复制相似问题