[英]WooCommerce how to overwrite the product quantity
如何使用以下代碼覆蓋當前數量輸入? 我不知道在函數中使用哪個鈎子。 我要更改產品頁面和購物籃上的數量
function quantity(){
global $product;
echo
'<div class="quantity">
<p>Quantity: </p>
<button class="increment">
<span></span><span></span>
</button>
<input type="text" value="1" min="1" max="' . $product->get_stock_quantity() . '">
<button class="decrement">
<span></span>
</button>
</div>';
}
我發現此功能允許我更改為數量輸入,但在購物籃頁面上導致以下錯誤。
致命錯誤:在null上調用成員函數get_stock_quantity()
這是代碼;
function woocommerce_quantity_input() {
global $product;
echo
'<div class="quantity">
<p>Quantity: </p>
<button class="increment">
<span></span><span></span>
</button>
<input type="text" value="1" min="1" max="' . $product->get_stock_quantity() . '">
<button class="decrement">
<span></span>
</button>
</div>';
}
這是當前輸入的數量。
這就是我想要的樣子;
我上面的代碼將進行此更改,但會在購物籃頁面上導致錯誤
您必須覆蓋WooCommerce購物車模板才能更改此輸入,如此處所述: https : //docs.woocommerce.com/document/template-structure/#section-1
您可以在plugins / woocommerce / templates / cart / cart.php中的cart.php中找到此輸入代碼。 復制此模板並將其粘貼到主題根目錄的woocommerce目錄中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.