woocommerce排除州免费送货(澳大利亚) [英] woocommerce exclude state free shipping (australian states)

查看:94
本文介绍了woocommerce排除州免费送货(澳大利亚)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将woocommerces排除在免费送货(澳大利亚站点)代码段之外,但是却遇到此错误:

I'm trying to implement woocommerces exclude states from free shipping (Australian Site) snippet but am running into this error:

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

'Fatal error: Call to a member function get_shipping_state() on a non-object in /home/bpcsport/public_html/wp-content/plugins/wa-exclude/wa-exclude.php on line 30'

我的客户需要将西澳大利亚州排除在他们通过woocommerce提供的免费送货交易之外.如果我将其放入主题function.php或通过插件格式,都会收到错误消息.

My client needs to exclude Western Australia from the free-shipping deal they offer through woocommerce. I get the error either way if I put it in my themes function.php or via plug-in format.

我也尝试了以下方法,但无济于事.

I've also tried the following method to no avail.

如何禁用某些州的免费送货?

这是插件中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;
}


?>

推荐答案

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

I've made an plugin which allow advanced user configurations. Altough it includes only US states, you can configure country and postal code conditions.

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

I don't know if this meets you requirements, but might worth checking out: http://wordpress.org/plugins/woocommerce-advanced-free-shipping/

这篇关于woocommerce排除州免费送货(澳大利亚)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆