woocommerce排除国家免费送货(澳大利亚州)(woocommerce exclude sta

2019-10-18 18:57发布

我试图实现woocommerces排除美国从免费送货(澳大利亚网站)片断,但我遇到了此问题:

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

我的客户需要从他们通过woocommerce提供免费送货的交易排除西澳大利亚州。 我得到的错误无论哪种方式,如果我把它放在我的主题function.php或通过插件格式。

我也尝试下面的方法都无济于事。

我怎样才能为特定国家禁用免费送货?

这是从woocommerce的片段,是在插件

/**
 * 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;
}


?>

Answer 1:

我做了一个插件,它允许高级用户配置。 Altough它仅包括美国各州,您可以配置国家和邮政编码条件。

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



文章来源: woocommerce exclude state free shipping (australian states)