繁体   English   中英

WooCommerce向国际客户发货的通知

[英]WooCommerce shipping notice to International customers

我需要在结帐时添加发货通知,并且我有以下代码:

// adds order note at checkout page     
function notice_shipping() {
echo '<p id="allow">Please allow 5-10 business days for delivery after order processing.</p>';
}

add_action( 'woocommerce_before_order_notes', 'notice_shipping' );

我只需要知道是否可以将通知仅限于我的国际客户? 我不介意列出每个国家,加拿大将是一个很好的开始。

我已经看过$woocommerce->customer->get_shipping_country()但不完全确定如何在我的functions.php中实现它,以及Woocommerce在每个国家/地区使用什么代码?

谢谢你的协助!

这是您重新访问的代码,其中包含一些jQuery,因为客户并不总是注册的,并且您在任何情况下都不知道将选择哪个国家作为发货国家。

这是该代码:

function notice_shipping(){
    ?>

    <script>
        jQuery(document).ready(function($){

            // Set the country code (That will NOT display the message)
            var countryCode = 'FR';

            var adressType =  'billing';

            // Detecting If shipping Country is going to be used
            $('#ship-to-different-address-checkbox').click(function(){

                if($('.shipping_address').css( 'display' ) == 'none'){
                    adressType = 'billing';
                } else {
                    adressType = 'shipping';
                }
                // console.log($adressType);
            });

            // Showing or hidding the message
            $('select#billing_country, select#shipping_country').change(function(){

                if(adressType == 'billing') {
                    selectedCountry = $('select#billing_country').val();
                }
                else if(adressType == 'shipping') {
                    selectedCountry = $('select#shipping_country').val();
                }

                if( selectedCountry == countryCode ){
                    $('.shipping-notice').hide();
                    // console.log('hide');
                }
                else {
                    $('.shipping-notice').show();
                    // console.log('show');
                }
                // console.log(selectedCountry);
            });
        });
    </script>

    <?php

    echo '<p id="allow" class="shipping-notice" style="display:none">Please allow 5-10 business days for delivery after order processing.</p>';
}
add_action( 'woocommerce_before_order_notes', 'notice_shipping' );

这段代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中。

此代码已经过测试,功能齐全。

您可以在此处看到原始演示 (临时) 在这里,不会在结帐时显示消息的所选国家是法国。

我认为您不能保证在woocommerce_before_order_notes上知道客户的地址。 您可以尝试以下方法,但是我不确定直到客户提交帐单地址后它才能起作用。

// adds order note at checkout page     
function notice_shipping( $checkout ) {
   $country = WC()->customer->get_shipping_country();
   if( $country != 'US' ){
       echo '<p id="allow">Please allow 5-10 business days for delivery after order processing.</p>';
    }
}

add_action( 'woocommerce_before_order_notes', 'notice_shipping' );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM