【问题标题】:How to implement the free shipping on specific product in woocommerce and set the default shipping如何在woocommerce中实现特定产品的免费送货并设置默认送货
【发布时间】:2021-05-01 04:22:03
【问题描述】:
function reset_default_shipping_method( $method, $available_methods ) 
{
   foreach( WC()->cart->get_cart() as $cart_item ) {
     $product_in_cart = $cart_item['product_id'];
     if($product_in_cart == '12101' ){
        $default_method = 'free_shipping:13'; 
     } else{
        unset( $available_methods['free_shipping:13'] );
     }
   }          
  return $default_method;   
}

add_filter('woocommerce_shipping_chosen_method', 'reset_default_shipping_method', 10, 2);

【问题讨论】:

    标签: php wordpress woocommerce product shipping


    【解决方案1】:
    function reset_default_shipping_method( $method, $available_methods ) {
      foreach( WC()->cart->get_cart() as $cart_item ) {
        $product_in_cart = $cart_item['product_id'];
        if($product_in_cart == '12101' ){
          $default_method = 'free_shipping:13'; 
        }else{
          unset( $available_methods['free_shipping:13'] );
        }
      }          
      return $default_method;   
        
    } add_filter('woocommerce_shipping_chosen_method', 'reset_default_shipping_method', 10, 2);
    

    【讨论】:

      猜你喜欢
      • 2021-12-10
      • 1970-01-01
      • 2015-12-06
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-01
      相关资源
      最近更新 更多