1 回答

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
您沒(méi)有woocommerce_quantity_input()
像在cart/cart.php
模板文件中那樣將必要的參數(shù)設(shè)置到函數(shù)中……下面將顯示一個(gè)輸入字段,其中包含結(jié)帳頁(yè)面中的當(dāng)前數(shù)量以替換數(shù)量字符串:
add_filter( 'woocommerce_checkout_cart_item_quantity', 'qty_input_field_on_checkout', 20, 3 );
function qty_input_field_on_checkout( $quantity_html, $cart_item, $cart_item_key ) {
? ? $_product = $cart_item['data'];
? ? if ( $_product->is_sold_individually() ) {
? ? ? ? $product_quantity = sprintf( '1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key );
? ? } else {
? ? ? ? $product_quantity = woocommerce_quantity_input(
? ? ? ? ? ? array(
? ? ? ? ? ? ? ? 'input_name'? ?=> "cart[{$cart_item_key}][qty]",
? ? ? ? ? ? ? ? 'input_value'? => $cart_item['quantity'],
? ? ? ? ? ? ? ? 'max_value'? ? => $_product->get_max_purchase_quantity(),
? ? ? ? ? ? ? ? 'min_value'? ? => '0',
? ? ? ? ? ? ? ? 'product_name' => $_product->get_name(),
? ? ? ? ? ? ),
? ? ? ? ? ? $_product,
? ? ? ? ? ? false
? ? ? ? );
? ? }
? ? return '<br><span class="product-quantity"><strong>' . __( 'Qty') . ': </strong></span>' . $product_quantity;
}
代碼進(jìn)入您的活動(dòng)子主題(或活動(dòng)主題)的 functions.php 文件。測(cè)試和工作。
現(xiàn)在這將只允許顯示數(shù)量字段,但不允許更新產(chǎn)品數(shù)量,因?yàn)樗瞧渌鼜?fù)雜的東西。
- 1 回答
- 0 關(guān)注
- 158 瀏覽
添加回答
舉報(bào)