WooCommerce shipping cost based on cart item count

前端 未结 3 1845
长情又很酷
长情又很酷 2021-01-23 07:01

I want to count shipping cost based on number of products add on cart like,

If I purchase one mobile then it will count shipping cost as 2.5 and after more than two or t

3条回答
  •  故里飘歌
    2021-01-23 07:35

    You can add a custom fee: Add to theme functions.php or use a plugin

    add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
    
    function woocommerce_custom_surcharge() {
      global $woocommerce;
    
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
    
        $price_per_mobile = 2.5;
        $shipcharge = ( $woocommerce->cart->cart_contents_total * $price_per_mobile);   
        $woocommerce->cart->add_fee( 'Total Shipping Cost', $shipcharge, true, '' );
    
    }
    

提交回复
热议问题