我正尝试使用客户电子邮件地址作为他们自己的优惠券代码,并享有特别折扣。为了达到这个目的,我尝试了以下代码,但没有发生任何显示错误Call to undefined function get_currentuserinfo()
。是否有可能使用优惠券代码几乎不像定制post_type
保存?如何在woocommerce中使用客户电子邮件地址作为自己的优惠券代码
这是我到目前为止所尝试的代码。
global $current_user;
get_currentuserinfo();
$user_email = $current_user->user_email ;
$coupon_code = $user_email; // Code
$amount = '10'; // Amount
$discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
$coupon = array(
'post_title' => $coupon_code,
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'shop_coupon'
);
$new_coupon_id = wp_insert_post($coupon);
// Add meta
update_post_meta($new_coupon_id, 'discount_type', $discount_type);
update_post_meta($new_coupon_id, 'coupon_amount', $amount);
update_post_meta($new_coupon_id, 'individual_use', 'no');
update_post_meta($new_coupon_id, 'product_ids', '');
update_post_meta($new_coupon_id, 'exclude_product_ids', '');
update_post_meta($new_coupon_id, 'usage_limit', '');
update_post_meta($new_coupon_id, 'expiry_date', '');
update_post_meta($new_coupon_id, 'apply_before_tax', 'yes');
update_post_meta($new_coupon_id, 'free_shipping', 'no');
从'get_currentuserinfo()'更改为'wp_get_current_user()'。第一个从4.5开始已被弃用(假设你比这更高)。 https://codex.wordpress.org/Function_Reference/get_currentuserinfo&https://codex.wordpress.org/wp_get_current_user –