は、内部にいくつかの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ファイルに入るか、また、どのプラグインファイルに。
このコードはテスト済みで、完全に機能しています。
see here a raw demo(一時)です。 ここでチェックアウト時にメッセージを表示しない国はフランスです。
ニース!私はJSがもっと良い解決策かもしれないと思っていたが、それを肉付けする時間はなかった。 – helgatheviking
@helgathevikingありがとう:)私はまた、新しく非常に複雑な新しいWooCommerceプロジェクトにちょっと忙しかった。だから私の答えは遅く到着したのです。あなたの答えは素晴らしいです! – LoicTheAztec
うわー、ありがとう!まさに私が必要なもの! – Xenocide122