首页 文章

woocommerce排除州免费送货(澳大利亚州)

提问于
浏览
1

我正在尝试实现woocommerces排除免费送货(澳大利亚网站)片段的状态,但我遇到了这个错误:

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

我的客户需要将Western Australia从他们通过woocommerce提供的免费送货协议中排除 . 如果我将它放在我的主题function.php中或通过插件格式,我会得到错误 .

我也试过以下方法无济于事 .

How can I disable free shipping for particular states?

This is the snippet from woocommerce that is in the plug-in

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


?>

1 回答

相关问题