【发布时间】:2020-12-21 14:36:42
【问题描述】:
创建了这个 jQuery 以在我的 wordpress 网站中添加额外的价格:
jQuery(document).ready( function(){
var totprice = jQuery(".order-total .woocommerce-Price-amount.amount").text().replace('$','').replace(',','');
var leaseprice = (Number(totprice)) * (0.0198);
jQuery(".woocommerce-checkout-review-order-table tbody").append("<tr class='lp-total'><td class='lp-text'>Estimated Commercial Lease Total: </td>" + "<td class='lp-price'>" + "$" + leaseprice.toFixed(1) + "</td>"+ "</tr>");
});
html:
<table class="shop_table woocommerce-checkout-review-order-table">
<thead>
<tr>
<th class="product-name">Product</th>
<th class="product-total">Subtotal</th>
</tr>
</thead>
<tbody>
<tr class="cart_item">
<td class="product-name"> Max-EV 20 <strong class="product-quantity">× 1</strong> </td>
<td class="product-total"> <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>30,950.00</span>
</td>
</tr>
</tbody>
<tfoot>
<tr class="cart-subtotal">
<th>Subtotal</th>
<td><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>30,950.00</span>
</td>
</tr>
<tr class="order-total">
<th>Total</th>
<td><strong><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>30,950.00</span></strong> </td>
</tr>
</tfoot>
</table>
它在控制台中工作得很好,但是一旦我将它保存在 custom.js 文件中并按下刷新按钮以检查它是否工作,我会在 jQuery 中看到 html 一秒钟然后它会自动隐藏。
请注意,如果我将 html 附加到同一页面上的其他任何位置,它可以正常工作。但是在这里我试图将它附加到一个标签中,当我这样做时,就会出现这个问题。
jQuery 代码有问题吗?
【问题讨论】:
标签: javascript jquery wordpress woocommerce checkout