每次在 woocommerce 中生成动态优惠券代码
Generate Dynamic couponcode every time in woocommerce
我正在使用此 https://docs.woocommerce.com/document/create-a-coupon-programatically/ 代码以编程方式生成优惠券代码。
效果不错。但是每次生成 UNIQUECODE 同名代码。我想每次都生成不同的代码。
示例:UNIQUECODE12、UNIQUECODE14、UNIQUECODE16 等
所以请帮我看看这怎么可能。
谢谢。
您可以使用作为优惠券计数器的 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
我正在使用此 https://docs.woocommerce.com/document/create-a-coupon-programatically/ 代码以编程方式生成优惠券代码。
效果不错。但是每次生成 UNIQUECODE 同名代码。我想每次都生成不同的代码。
示例:UNIQUECODE12、UNIQUECODE14、UNIQUECODE16 等
所以请帮我看看这怎么可能。
谢谢。
您可以使用作为优惠券计数器的 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