【问题标题】:woocommerce exclude state free shipping (australian states)woocommerce 不包括国家免费送货(澳大利亚各州)
【发布时间】:2013-10-23 04:06:09
【问题描述】:

我正在尝试实施 woocommerces 从免费送货(澳大利亚网站)sn-p 中排除州,但遇到此错误:

'致命错误:在非对象上调用成员函数 get_shipping_state() /home/bpcsport/public_html/wp-content/plugins/wa-exclude/wa-exclude.php 在第 30 行'

我的客户需要将西澳大利亚排除在他们通过 woocommerce 提供的免费送货服务之外。如果我把它放在我的主题 function.php 或通过插件格式,我都会得到错误。

我也试过下面的方法,没用。

How can I disable free shipping for particular states?

这是插件中来自 woocommerce 的 sn-p

/**
 * Hide ALL shipping options when free shipping is available and customer is NOT in certain states
 * Hide Free Shipping if customer IS in those states
 *
 * Change $excluded_states = array( 'AK','HI','GU','PR' ); to include all the states that DO NOT have free shipping
 */

add_filter( 'woocommerce_available_shipping_methods', 'hide_all_shipping_when_free_is_available' , 10, 1 );

/**
* Hide ALL Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_all_shipping_when_free_is_available( $available_methods ) {

  $excluded_states = array( 'WA' );

    if( isset( $available_methods['free_shipping'] ) AND !in_array( $woocommerce->customer->get_shipping_state(), $excluded_states ) ) :

        // Get Free Shipping array into a new array
        $freeshipping = array();
        $freeshipping = $available_methods['free_shipping'];

        // Empty the $available_methods array
        unset( $available_methods );

        // Add Free Shipping back into $avaialble_methods
        $available_methods = array();
        $available_methods[] = $freeshipping;

    endif;

    if( isset( $available_methods['free_shipping'] ) AND in_array( $woocommerce->customer->get_shipping_state(), $excluded_states ) ) {

        // remove free shipping option
        unset( $available_methods['free_shipping'] );

    }

    return $available_methods;
}


?>

【问题讨论】:

    标签: wordpress woocommerce shipping states


    【解决方案1】:

    我制作了一个允许高级用户配置的插件。虽然它只包括美国各州,但您可以配置国家和邮政编码条件。

    我不知道这是否符合您的要求,但可能值得一试:http://wordpress.org/plugins/woocommerce-advanced-free-shipping/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 2022-08-14
      • 2020-07-28
      • 2013-12-27
      • 1970-01-01
      • 2015-05-03
      相关资源
      最近更新 更多