从优惠券代码WooCommerce

时间:2017-11-27 17:56:15

标签: php wordpress woocommerce coupon

我之前曾问过this question但它没有回答如何从WooCommerce中的优惠券中检索数据的问题。这两个问题都涉及优惠券,但first question询问如何设置元数据,此问题询问您如何检索数据。

我试图通过优惠券代码从WooCommerce获取优惠券的详细信息。但是,我不确定如何尝试这样做。

我已经尝试过以下代码。但是,它给了我错误Call to undefined function WC_Coupon()

$coupon_code = 'save10percent';
global $woocommerce;
$c = WC_Coupon($coupon_code);

如何获取优惠券的详细信息?

1 个答案:

答案 0 :(得分:2)

我明白了。为了使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
相关问题