我有一种含有多种成分的披萨。如果用户勾选“添加成分”框,则选项会出现,因为下拉默认为“无”。我需要将“无”选项隐藏在购物车和结帐中。
我已将它们隐藏在购物车页面中,但它们仍显示在桅顶车和结帐中。
以下是一些显示成分的代码:
<li>Add Ingredients?</li>
</ul>
</dd>
<dt class="variation-GreenOlives">Green Olives:</dt>
<dd class="variation-GreenOlives">
<p>Whole Pizza ($1.00)</p>
</dd>
<dt class="variation-RipeOlives">Ripe Olives:</dt>
<dd class="variation-RipeOlives">
<p>None</p>
</dd>
<dt class="variation-SlicedTomatoes">Sliced Tomatoes:</dt>
<dd class="variation-SlicedTomatoes">
<p>None</p>
</dd>
<dt class="variation-FreshMushrooms">Fresh Mushrooms:</dt>
<dd class="variation-FreshMushrooms">
<p>None</p>
</dd>
<dt class="variation-ArtichokeHearts">Artichoke Hearts:</dt>
<dd class="variation-ArtichokeHearts">
<p>None</p>
</dd>
<dt class="variation-CannedMushrooms">Canned Mushrooms:</dt>
<dd class="variation-CannedMushrooms">
<p>None</p>
</dd>
<dt class="variation-FreshBasil">Fresh Basil:</dt>
<dd class="variation-FreshBasil">
<p>None</p>
</dd>
<dt class="variation-Spinach">Spinach:</dt>
<dd class="variation-Spinach">
<p>None</p>
</dd>
<dt class="variation-Pepperjack">Pepperjack:</dt>
<dd class="variation-Pepperjack">
<p>None</p>
</dd>
<dt class="variation-ExtraCheese">Extra Cheese:</dt>
<dd class="variation-ExtraCheese">
<p>None</p>
</dd>
<dt class="variation-Cheddar">Cheddar:</dt>
<dd class="variation-Cheddar">
<p>None</p>
</dd>
<dt class="variation-Swiss">Swiss:</dt>
<dd class="variation-Swiss">
<p>None</p>
</dd>
以下是隐藏购物车页面上“无”选项的代码:
function hideNone(){
$(document).ready(function(){
$("dd>p:contains('None')").hide() && $("dd").prev().hide();
});
}
因此,即使代码在订单显示的所有三个位置上都相同,但此代码仅将其隐藏在购物车页面上。我在本地安装上使用woocommerce和gravity表单。谢谢你的帮助。
答案 0 :(得分:0)
我认为问题是您已声明函数hideNone()
并且尚未调用该函数。 $( document ).ready()
实际上用于在加载文档时调用函数,这意味着不需要是函数定义。请参阅文档。
$(document).ready(function() {
$("dd>p:contains('None')").hide() && $("dd").prev().hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<dt class="variation-GreenOlives">Green Olives:</dt>
<dd class="variation-GreenOlives">
<p>Whole Pizza ($1.00)</p>
</dd>
<dt class="variation-RipeOlives">Ripe Olives:</dt>
<dd class="variation-RipeOlives">
<p>None</p>
</dd>
<dt class="variation-SlicedTomatoes">Sliced Tomatoes:</dt>
<dd class="variation-SlicedTomatoes">
<p>None</p>
</dd>
<dt class="variation-FreshMushrooms">Fresh Mushrooms:</dt>
<dd class="variation-FreshMushrooms">
<p>None</p>
</dd>
<dt class="variation-ArtichokeHearts">Artichoke Hearts:</dt>
<dd class="variation-ArtichokeHearts">
<p>None</p>
</dd>
<dt class="variation-CannedMushrooms">Canned Mushrooms:</dt>
<dd class="variation-CannedMushrooms">
<p>None</p>
</dd>
<dt class="variation-FreshBasil">Fresh Basil:</dt>
<dd class="variation-FreshBasil">
<p>None</p>
</dd>
<dt class="variation-Spinach">Spinach:</dt>
<dd class="variation-Spinach">
<p>None</p>
</dd>
<dt class="variation-Pepperjack">Pepperjack:</dt>
<dd class="variation-Pepperjack">
<p>None</p>
</dd>
<dt class="variation-ExtraCheese">Extra Cheese:</dt>
<dd class="variation-ExtraCheese">
<p>None</p>
</dd>
<dt class="variation-Cheddar">Cheddar:</dt>
<dd class="variation-Cheddar">
<p>None</p>
</dd>
<dt class="variation-Swiss">Swiss:</dt>
<dd class="variation-Swiss">
<p>None</p>
</dd>