【问题标题】:Why does not work for default shipping method? For WooCommerce为什么不适用于默认运输方式?对于 WooCommerce
【发布时间】:2019-06-22 17:59:09
【问题描述】:

我想默认 DHL。但它不起作用,这是为什么呢?在 WordPress 的 WooCommerce 中。

您可以在此处查看:img。方式-functions.php

function reset_default_shipping_method( $method, $available_methods ) {

    if ( ! empty( $method ) ) {
        return $method;
    }        

    $method = 'shipping_method_0_flat_rate9';

    return $method;
}

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

【问题讨论】:

    标签: wordpress methods woocommerce default shipping


    【解决方案1】:

    过滤器已更新,您应该试试这个。 我已经对其进行了测试,它对我有用。

    此外,默认运费存储在您的会话中,因此如果您想测试它,可以从新浏览器尝试或注销并重新登录。

     function prefix_reset_default_shipping_method( $default, $package, $chosen_method ) {
    
            if( $default !== 'flat_rate:9')
                $default = 'flat_rate:9';
    
            return $default;
    
        }
    
        add_filter('woocommerce_shipping_chosen_method', 'prefix_reset_default_shipping_method', 10, 3);
    

    【讨论】:

      【解决方案2】:
      function reset_default_shipping_method( $method, $available_methods ) {
          $default_method = 'wf_fedex_woocommerce_shipping:FEDEX_GROUND'; //provide here the service name which will selected default
          if( array_key_exists($method, $available_methods ) )
              return $default_method;
          else
              return $method;
      }
      add_filter('woocommerce_shipping_chosen_method', 'reset_default_shipping_method', 10, 2);
      

      将此添加到您的主题的functions.php 更改$default_method var。

      来源:https://www.xadapter.com/set-default-shipping-method-woocommerce/

      【讨论】:

        猜你喜欢
        • 2014-12-22
        • 2016-08-07
        • 1970-01-01
        • 2017-03-18
        • 1970-01-01
        • 2018-01-27
        • 1970-01-01
        • 2011-03-25
        相关资源
        最近更新 更多