WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
How to apply an automatic discount in WooCommerce based product weight (1 post)

  1. will2
    Member
    Posted 7 months ago #

    hello
    I want to apply automatically discount coupons without the enter the buyer. if either of these two conditions shipping will be free, each condition has a coupon
    If I have a coupon works just fine, if I put two coupons does not work
    Does anyone know why it does not work with two coupons?
    thank you very much greetings

    add_action('woocommerce_before_cart_table', 'descuento_loncheado_kebab');
    function descuento_loncheado_kebab( ) {
        global $woocommerce;
        global $total_weight;
    
    	//$woocommerce->cart->remove_coupons( sanitize_text_field( $coupon_code ));
    
       if($total_weight >= 190 ) {
            $coupon_code = '190';
    		if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon_code ))) {
    	            $woocommerce->show_messages();
    	        }
        }
    	else
    	{
    		if($total_weight >= 80)
    	    {
    	        $coupon_code = '80';
    	        if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon_code ))) {
    	            $woocommerce->show_messages();
    	        }
    
    	    }
    	 }
    }
    
    add_action('woocommerce_before_cart_table', 'eliminar_descuento_loncheado_kebab');
    function eliminar_descuento_loncheado_kebab( ) {
        global $woocommerce;
        global $total_weight;
    
        if(($total_weight < 80))
        {
        	$coupon_code = '80';
    		$woocommerce->cart->get_applied_coupons();
        	if (!$woocommerce->cart->remove_coupons( sanitize_text_field( $coupon_code ))) {
            	$woocommerce->show_messages();
        	}
    
    	}
    	else
    	{
    		if(($total_weight < 190))
    		{
    	        	$coupon_code = '190';
    	        	$woocommerce->cart->get_applied_coupons();
    
    			if (!$woocommerce->cart->remove_coupons( sanitize_text_field( $coupon_code ))) {
                		$woocommerce->show_messages();
            	}
            	$woocommerce->cart->calculate_totals();
    
    	 }		
    
          }
    
    }

    http://wordpress.org/plugins/woocommerce/

Reply

You must log in to post.

About this Plugin

About this Topic