Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 在woocommerce中对优惠券手动应用电子邮件限制的代码_Wordpress_Woocommerce - Fatal编程技术网

Wordpress 在woocommerce中对优惠券手动应用电子邮件限制的代码

Wordpress 在woocommerce中对优惠券手动应用电子邮件限制的代码,wordpress,woocommerce,Wordpress,Woocommerce,因此,我有一个使用wordpress和woo commerce的电子商务网站,现在使用智能优惠券woo commerce插件扩展是否有办法创建信用优惠券/礼品卡(最初没有电子邮件限制)并在首次使用礼品卡时手动指定当前用户的电子邮件作为其电子邮件限制 我正在尝试创建一个vooucher系统,使用礼品卡作为代金券在我的商店购买产品。由于您没有任何代码来显示您正在使用的产品,请尝试此方法 $coupon_code = 'some-code-I-created'; $user = wp_get_curr

因此,我有一个使用wordpress和woo commerce的电子商务网站,现在使用智能优惠券woo commerce插件扩展是否有办法创建信用优惠券/礼品卡(最初没有电子邮件限制)并在首次使用礼品卡时手动指定当前用户的电子邮件作为其电子邮件限制


我正在尝试创建一个vooucher系统,使用礼品卡作为代金券在我的商店购买产品。

由于您没有任何代码来显示您正在使用的产品,请尝试此方法

$coupon_code = 'some-code-I-created';
$user = wp_get_current_user();//Get the current user object
$coupon = new WC_Coupon( $coupon_code );//Get the coupon object
$emails = $coupon->get_email_restrictions();//Returns an empty array or array of emails
$emails[] = strtolower($user->billing_email);//Add user's billing email address to the array
$emails = array_filter($emails);//Remove empty values
array_unique($emails);//Remove any duplicate values
$coupon->set_email_restrictions($emails);//Set the coupon's array with the updated array
$coupon->save();//Save the coupon
如果我批量添加电子邮件地址(比如使用array_merge()而不是一次添加一个地址),在使用优惠券对象更新优惠券对象之前,最好先删除任何空值或重复值,以确保数组是干净的


此外,WooCommerce会比较优惠券中所有小写字母的账单地址,但不会比较优惠券中的受限电子邮件,因此在将其添加到优惠券时,请确保将其添加为所有小写字母,以便正确验证。这个错误将来可能会被修复,但在此之前…

我会向一个woo commerce特定论坛提出这个问题。我几天前尝试过,但没有得到任何帮助。所以现在我在这里。