第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 WooCommerce Checkout 上為每個(gè)產(chǎn)品添加數(shù)量輸入字段

在 WooCommerce Checkout 上為每個(gè)產(chǎn)品添加數(shù)量輸入字段

PHP
BIG陽(yáng) 2023-05-26 16:25:08
我想了解如何在結(jié)帳頁(yè)面上添加數(shù)量輸入字段,這樣,客戶(hù)就可以更改每種產(chǎn)品的數(shù)量。這是我到目前為止得到的:add_filter( 'woocommerce_checkout_cart_item_quantity', 'qty_and_qty_change_on_checkout', 20, 3 );function qty_and_qty_change_on_checkout( $quantity_html, $cart_item, $cart_item_key ) {    return '<br>    '.woocommerce_quantity_input().'    <span class="product-quantity">    ' . sprintf( '<b>Qty:</b> %s', $cart_item['quantity'] ) . '    </span>';}但這給了我一個(gè)錯(cuò)誤,即使woocommerce_quantity_input()它是官方功能嗎?錯(cuò)誤是:Notice: Undefined index: product in /wp-content/plugins/woocommerce/includes/wc-template-functions.php on line 1670
查看完整描述

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ù)雜的東西。


查看完整回答
反對(duì) 回復(fù) 2023-05-26
  • 1 回答
  • 0 關(guān)注
  • 158 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)