簡體   English   中英

WooCommerce-在結帳時顯示購物車產品總數

[英]WooCommerce - Display total number of cart products in checkout

我正在嘗試在結帳頁面上顯示客戶在其購物車中擁有的商品總數。

我已經閱讀過文檔 ,我需要使用get_cart_contents_count但是當我嘗試使用get_cart_contents_count時,無論我有多少物品,它都會輸出1。

注意:get_cart_contents_count( )獲取購物車中的物品數量。返回整數”

我的代碼是:

add_action( 'woocommerce_before_checkout_billing_form', 'my_custom_checkout_field' );

function my_custom_checkout_field( $checkout ) {
    $_cartQty = count( WC()->cart->get_cart_contents_count( ) );
    echo $_cartQty;
} 

任何幫助將不勝感激,因為我認為我很聰明地進入了這個階段。

您有一個使它不起作用的計數-試試這個:

function my_custom_checkout_field( $checkout ) {
    $_cartQty = WC()->cart->get_cart_contents_count( );
    echo $_cartQty;
} 

如果我是你,我將其更改為:

function my_custom_checkout_field( $checkout ) {        
    return WC()->cart->get_cart_contents_count();
} 

我永遠也不會從這樣的函數中得到回應-像這樣將php和HTML結合起來通常沒有任何好處。

我會<?= $class->my_custom_checkout_field() ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM