Apply coupon discount via GET method in URL even if cart is empty in WooCommerce

后端 未结 3 1681
余生分开走
余生分开走 2020-12-31 18:27

I have a plugin that sends an advocates referral coupon code to e-mails that they enter. When the audience receives this email I\'d like to create a flow where they can clic

3条回答
  •  悲&欢浪女
    2020-12-31 19:04

    add_action('woocommerce_before_cart', 'discount');
    function discount( ) {
        global $woocommerce;
        $code= $_GET["code"];
       if(!empty($code)){       
        if(WC()->session->set( 'applied_coupons', $code )){ 
        echo '
    Applied coupon!
    '; } } }

提交回复
热议问题