代码之家  ›  专栏  ›  技术社区  ›  user7132484

WooCommerce-在允许使用优惠券之前检查Mailchimp订户

  •  0
  • user7132484  · 技术社区  · 8 年前

    我想解决一个关于MailChimp和WooCommerce整合的难题,我们的情况是这样的,我们使用MailChimp发送静态优惠券,因为我们内部的CRM,它们是静态的。一旦发送了静态优惠券,人们就可以在我们的网站上使用它,然而,没有任何措施可以阻止与未注册的人共享此代码,因此我们希望这样,当你使用特定优惠券时,它会检查你在网站上使用的电子邮件地址与Mailchimp,如果你在列表中,优惠券适用,否则它不会,我只是想看看这是否可能,如果可能,怎么可能?

    我们在这个问题上迷失了方向,所以可以在这里使用社区的帮助,我们觉得这个线程在未来也可能对其他人有用,感谢它是特定的,但可能在以后的安全中使用。

    非常感谢!

    1 回复  |  直到 8 年前
        1
  •  0
  •   Rich    8 年前

    Drewms Mailchimp wrapper 或者类似地,您可以执行以下操作,不要忘记包含MailChimp API密钥和列表ID。

    include 'Mailchimp.php';
    use \DrewM\MailChimp\MailChimp;
    $MailChimp = new MailChimp('your**api***key');
    
    function emailExistsMc($subscriberMail, $list_id){
        global $MailChimp;
        $subscriber_hash = $MailChimp->subscriberHash($subscriberMail);
        $result = $MailChimp->get("lists/$list_id/members/$subscriber_hash");
        if($result['status'] == 'subscribed') {
         return true;
        } else {
         return false;
        }
    
    }    
    
    add_action('woocommerce_checkout_process', 'my_themes_guest_email_checker');
    
        function my_themes_guest_email_checker() {
            global $woocommerce;
    
            $list_id = <list id here>;
    
            // Check checkout email address against MC list, if exists proceed
            if ( emailExistsMc($_POST['billing_email'], $list_id) ) {
    
            } else {
              $woocommerce->add_error( __('This coupon is not valid') );
            }
    
        }