2016-11-23 3 views
0

は私がWooCommerceによって生成されたコードの以下のビットが使用可能な配送オプションを表示する必要があります:最初のラジオボタンが選択されている場合特定のラジオボタンがチェックされている場合、残りのラジオボタンを無効にする方法はありますか?

<ul id="shipping_method"> 
<li> 
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate5" value="flat_rate:5" class="shipping_method" checked='checked' /> 
<label for="shipping_method_0_flat_rate5">Call 386-410-4757 for Shipping Quote</label>     </li> 
<li> 
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_wf_shipping_uspsd_express_mail" value="wf_shipping_usps:D_EXPRESS_MAIL" class="shipping_method" /> 
<label for="shipping_method_0_wf_shipping_uspsd_express_mail">Priority Mail Express&#8482; (USPS): <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#36;</span>22.95</span></label>     </li> 
<li> 
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_wf_shipping_uspsd_priority_mail" value="wf_shipping_usps:D_PRIORITY_MAIL" class="shipping_method" /> 
<label for="shipping_method_0_wf_shipping_uspsd_priority_mail">Priority Mail&#0174; (USPS): <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#36;</span>6.45</span></label> 
</li> 
</ul> 

私は何をできるようにする必要があることは無効ラジオボタン2と3です。

私は無駄にこれを試してみました:

$('.shipping_method').click(function(){ 
    if(this.value == 'flat_rate:5' && this.checked){ 
     console.log($('input[value=wf_shipping_usps:D_EXPRESS_MAIL], input[value=wf_shipping_usps:D_PRIORITY_MAIL]')); 
     $('input[value=wf_shipping_usps:D_EXPRESS_MAIL], input[value=wf_shipping_usps:D_PRIORITY_MAIL]').prop('disabled', true); 
    } 
    else{ 
     $('.shipping_method').not(this).prop('checked', false).prop('disabled', false); 
    } 
}); 

すべてのヘルプははるかに高く評価されるだろう!

おかげで、

シンシア意味AJAXによる

+1

名前付きグループからラジオボタンを1つだけ選択できると、他のラジオボタンを無効にすることは少し冗長に見えます。誤ってクリックすると選択を変更できないため、ユーザーにとって迷惑です。 –

+0

する必要があります。私はWoocommerceでオンラインで計算することができない出荷を求めるために必要な数少ない製品を持っています。これらの製品の場合のみ、Call for Shippingは配送オプションとして表示されます。 – Cynthia

答えて

0

WooCommerce負荷多くのものが、あなたはイベントの委任を使用する必要があります。

さらに、thisがjQuery関数の内部を表すものと誤解する可能性があるので、いくつかの小切手を修正しました。あなたは問題がある場合

// WordPress loads jQuery in noConflict mode, so 
// First be sure you can use the $ by wrapping inside of a 
// noConflict-safe document ready 
jQuery(function($) { 
    // Event delegation 
    $(document).on('click', '#shipping_method input', function() { 
     // Use jQuery .val() and jQuery .is() to check if it's the correct item 
     if($(this).val() == 'flat_rate:5' && $(this).is(':checked')) { 
      $('input.shipping_method').not('[value="flat_rate:5"]').prop('disabled', true); 
     } else { 
      $('input.shipping_method').not('[value="flat_rate:5"]').prop('checked', false).prop('disabled', false); 
     } 
    }); 
}); 

、:

最後に、あなたがそれらを特異的に識別するようにというし、無効になって、ほかのすべての入力をしたい、私はすべてを無効にするコードが、必要とされるものを変更しましたブラウザのデベロッパーコンソールを確認して問題の詳細を報告してください。そうでない場合は手助けすることは不可能です。

関連する問題