久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

根據(jù) WooCommerce 購物車中的購物車商品數(shù)量顯示消

Display message based on cart items count in WooCommerce cart(根據(jù) WooCommerce 購物車中的購物車商品數(shù)量顯示消息)
本文介紹了根據(jù) WooCommerce 購物車中的購物車商品數(shù)量顯示消息的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我想在 woocommerce_before_cartwoocommerce_before_cart_table 如果購物車中的商品總數(shù)小于X,也顯示差值.我所說的項(xiàng)目是指單個(gè)數(shù)量而不是產(chǎn)品線.

I'd like to display a message in either woocommerce_before_cart or woocommerce_before_cart_table if the total number of items in the cart is less than X, and also display the difference. By items I mean individual quantities not product lines.

如何添加對購物車中所有商品的數(shù)量求和并在總數(shù)小于指定數(shù)量時(shí)顯示消息的函數(shù)?

How can I add a function that sums the quantities of all items in the cart and displays a message if the total is less than the specified quantity?

示例:將數(shù)量設(shè)置為 30,購物車總共包含 27 件商品,因此消息會(huì)顯示如果您再訂購 3 件商品,您可以獲得..."等.但如果購物車已有 30 件或更多商品,則無需顯示任何消息.

Example: Set the number to 30, cart contains a total of 27 items, so a message would say 'If you order 3 more items you can get...' etc. But if the cart already has 30 or more items, then no message needs to show.

推薦答案

要根據(jù)購物車商品數(shù)量在購物車頁面上顯示自定義消息,請使用以下內(nèi)容:

To display a custom message on cart page based on number of cart items count, use the following:

// On cart page only
add_action( 'woocommerce_check_cart_items', 'custom_total_item_quantity_message' );
function custom_total_item_quantity_message() {
    $items_count = WC()->cart->get_cart_contents_count();
    $min_count   = 30;

    if( is_cart() && $items_count < $min_count ){
        wc_print_notice( sprintf( __("If you order %s more items you can get…", "woocommerce"), $min_count - $items_count ), 'notice' );
    }
}

代碼位于活動(dòng)子主題(或活動(dòng)主題)的 function.php 文件中.經(jīng)過測試和工作.

Code goes in function.php file of your active child theme (or active theme). Tested and work.

如果使用 woocommerce_before_cartwoocommerce_before_cart_table,當(dāng)更改數(shù)量或移除商品時(shí),剩余數(shù)量不會(huì)更新……嘗試:

If using woocommerce_before_cart or woocommerce_before_cart_table the remaining count will not be updated when changing quantities or removing items… Try:

add_action( 'woocommerce_before_cart', 'custom_total_item_quantity_message' );
function custom_total_item_quantity_message() {
    $items_count = WC()->cart->get_cart_contents_count();
    $min_count   = 30;

    if( is_cart() && $items_count < $min_count ){
        echo '<div class="woocommerce-info">';
        printf( __("If you order %s more items you can get…", "woocommerce"), $min_count - $items_count );
        echo '</div>';
    }
}

或:

add_action( 'woocommerce_before_cart_table', 'custom_total_item_quantity_message' );
function custom_total_item_quantity_message() {
    $items_count = WC()->cart->get_cart_contents_count();
    $min_count   = 30;

    if( is_cart() && $items_count < $min_count ){
        echo '<div class="woocommerce-info">';
        printf( __("If you order %s more items you can get…", "woocommerce"), $min_count - $items_count );
        echo '</div>';
    }
}

這篇關(guān)于根據(jù) WooCommerce 購物車中的購物車商品數(shù)量顯示消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗(yàn)證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產(chǎn)品中添加一個(gè)將更改價(jià)格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 亚洲精品短视频 | 日韩小视频 | 久久久久久国产一区二区三区 | 黄色毛片免费看 | 午夜天堂精品久久久久 | 久久三区| 日韩在线播放第一页 | 天天夜碰日日摸日日澡 | 亚洲精品在线91 | jizz亚洲人| 久久久www成人免费无遮挡大片 | 国产四虎| 激情久久网 | 日韩欧美亚洲 | 欧美黑人体内she精在线观看 | 久久久精 | 久久精品日产第一区二区三区 | 久久久久国产精品一区二区 | 亚洲成人在线免费 | 日韩欧美手机在线 | 欧美精品a∨在线观看不卡 国产精品久久国产精品 | 一区二区三区国产 | 久久黄网 | 国产伦精品一区二区三区四区视频 | 日本不卡一区二区三区在线观看 | 婷婷国产一区二区三区 | 久久免费精品视频 | 日韩在线免费看 | 亚洲一区二区三区四区五区午夜 | 日韩欧美一级精品久久 | 五月天激情综合网 | 久久精品青青大伊人av | 国产精品久久久久久久久免费樱桃 | 国产在线一区二区 | 亚洲精品高清视频在线观看 | 麻豆久久久 | av日韩一区 | 成人av网站在线观看 | 国产精品国产成人国产三级 | 不卡在线视频 | 欧美片网站免费 |