每次在woocommerce

时间:2018-01-24 05:59:10

标签: wordpress dynamic woocommerce coupon

我正在使用此https://docs.woocommerce.com/document/create-a-coupon-programatically/代码以编程方式生成优惠券代码。

这很好用。但每次生成 UNIQUECODE 相同的名称代码。我想每次生成不同的代码。

示例:UNIQUECODE12,UNIQUECODE14,UNIQUECODE16等。

所以请帮助我如何做到这一点。

感谢。

1 个答案:

答案 0 :(得分:1)

您可以使用优惠券计数器Options API创建WordPress选项。您可以在每次使用时访问和增加计数器。

<?php
add_option( 'coupon-count', 0 ); // only sets it if it isn't in the database
$coupon_count = get_option( 'coupon-count' ); // access count
$coupon_count++; // increment the count
update_option( 'coupon-count', $coupon_count ); // store the incremented count for
$coupon_code = 'UNIQUECODE' . '-' . $coupon_count; // Numbered Code