为了账号安全,请及时绑定邮箱和手机立即绑定

WooCommerce 中付费客户的自动折扣

WooCommerce 中付费客户的自动折扣

PHP
翻过高山走不出你 2021-06-29 13:57:27
我想向在我的网站上至少购买过一次的每个人自动应用折扣券。这是我尝试过的代码,但我在页面上遇到了致命错误...function has_bought( $customer_email ){    $orders = get_posts(array(        'numberposts' => -1,        'post_type' => 'shop_order',        'post_status' => array('wc-completed'),    )  );    $email_array = array();    foreach($orders as $order) {        $order_obj = wc_get_order($order->ID);        $order_obj_data = $order_obj->get_data();        array_push($email_array, $order_obj_data['billing']['email']);    }    if (in_array($customer_email, $email_array)) {        return true;    } else {        return false;    }}add_action( 'woocommerce_before_cart', 'apply_matched_coupons' );function apply_matched_coupons() {    global $woocommerce;    $coupon_code = '10fidelity'; // coupon code    if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;    if ( has bought() {        $woocommerce->cart->add_discount( $coupon_code );        $woocommerce->show_messages();    }}
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 193 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信