我需要在结账时添加发货通知,我有以下代码:
// 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()
,但不完全确定如何在我的函数中实现它。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 文件中或任何插件文件中。
此代码经过测试且功能齐全。
You can see here a raw demo (temporary). Here the chosen country that will not display the message on checkout is France.
关于php - WooCommerce 给国际客户的发货通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39841061/