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

WooCommerce 中選定產品類別的自定義產品價格后綴

Custom product price suffix for selected product categories in WooCommerce(WooCommerce 中選定產品類別的自定義產品價格后綴)
本文介紹了WooCommerce 中選定產品類別的自定義產品價格后綴的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想在 WooCommerce 中的價格標簽后顯示一段文字.我有一個適用于我的functions.php 的代碼,但它顯示在所有產品類別中.

I would like to display a piece of text after the price tag in WooCommerce. I have a code that is working for my functions.php, but it shows on all product categories.

我想知道是否有人知道如何使此自定義文本僅顯示選定的類別;或者甚至更好,未選擇的產品類別,因為會顯示文本的產品類別比不顯示的產品類別多得多.

I was wondering if someone knows how to make this custom text to show for only selected categories; or even better, unselected product categories as there are a lot more product categories that will display the text than the ones who doesn't.

我的實際代碼:

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
    $mt = ' per M/T';
    return $price . $mt;
}

推薦答案

試試下面的代碼,使用 has_term() 條件函數來定義產品類別:

Try the following code that uses has_term() conditional function for defined product categories:

add_filter( 'woocommerce_get_price_html', 'conditional_price_suffix', 20, 2 );
function conditional_price_suffix( $price, $product ) {
    // HERE define your product categories (can be IDs, slugs or names)
    $product_categories = array('t-shirts','hoodies');

    if( has_term( $product_categories, 'product_cat', $product->get_id() ) )
        $price .= ' ' . __('per M/T');

    return $price;
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.經測試有效.

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

要排除定義的產品類別,您將替換:

if( has_term( $product_categories, 'product_cat', $product->get_id() ) )

簡單地通過:

if( ! has_term( $product_categories, 'product_cat', $product->get_id() ) )

這篇關于WooCommerce 中選定產品類別的自定義產品價格后綴的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 欧美福利影院 | 午夜视频在线观看一区二区 | 中文字幕一区二区三区乱码在线 | 久久久久久久久久久蜜桃 | 欧洲高清转码区一二区 | 麻豆av网站 | av中文字幕在线 | 99精品免费 | 久久伦理电影 | 羞羞视频在线观看 | 99久久99热这里只有精品 | 一区二区三区国产 | 国产1区 | 久久99精品国产麻豆婷婷 | 国产精品国产成人国产三级 | 91porn成人精品 | 91精品国产日韩91久久久久久 | 91久久久久| 国产一区二区三区 | 激情免费视频 | 久久久久久色 | 色婷婷av99xx| 国产欧美精品区一区二区三区 | 成人在线网址 | 亚洲国产成人在线 | 亚洲精品一二三 | 亚洲精品一区国产精品 | 日韩精品av一区二区三区 | 怡红院免费的全部视频 | 精品一区视频 | 日韩成人在线播放 | 伦理午夜电影免费观看 | www,黄色,com | 成人国产精品久久久 | 亚洲国产一区二区三区 | 国产精品免费在线 | 成人av播放| 毛片免费看 | 中文字幕日韩一区 | 亚洲二区视频 | www.蜜桃av|