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

在 WooCommerce 購物車頁面中的每個產品下方添加運

Add Shipping class below each product in WooCommerce Shopping Cart page(在 WooCommerce 購物車頁面中的每個產品下方添加運輸類別)
本文介紹了在 WooCommerce 購物車頁面中的每個產品下方添加運輸類別的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經為我的產品配置了運輸等級.但我想在購物車頁面中的每個產品下方顯示它們.像這樣:

I've configure shipping class for my products. But I want to display them below each product in the shopping cart page. Something like this :

這可以通過編輯 PHP 來完成嗎?

Can this be done through editing the PHP?

推薦答案

要在購物車頁面中顯示產品運輸類別名稱,有多種方法:

To display the product shipping class name in cart page, there is many ways to do it:

1) 使用掛在 woocommerce_cart_item_name 過濾器鉤子中的自定義函數,這樣:

1) Using a custom function hooked in woocommerce_cart_item_name filter hook, this way:

add_filter( 'woocommerce_get_item_data', 'shipping_class_in_item_name', 20, 2 );
function shipping_class_in_item_name( $cart_data, $cart_item ) {

    $custom_items = array();

    $product = $cart_item['data']; // Get the WC_Product object instance
    $shipping_class_id = $product->get_shipping_class_id(); // Shipping class ID
    $shipping_class_term = get_term( $shipping_class_id, 'product_shipping_class' );
    $label = __( 'Shipping class', 'woocommerce' );

    // Checking (To display it in checkout page too, remove below " || is_checkout()" )
    if( empty( $shipping_class_id ) || is_checkout() )
        return $cart_data; // Return default cart dat (in case of)

    // If product or variation description exists we display it
    $custom_items[] = array(
        'key'      => $label,
        'display'  => $shipping_class_term->name,
    );

    // Merging shipping class name and product variation attributes + values (if there are some)
    if( ! empty( $cart_data ) ) $custom_items = array_merge( $custom_items, $cart_data );

    return $custom_items;
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.

此代碼已經過測試且有效.

This code is tested and works.

2) 使用掛在 woocommerce_cart_item_name 過濾器鉤子中的自定義函數,這樣:

2) Using a custom function hooked in woocommerce_cart_item_name filter hook, this way:

add_filter( 'woocommerce_cart_item_name', 'shipping_class_in_item_name', 20, 3);
function shipping_class_in_item_name( $item_name, $cart_item, $cart_item_key ) {
    // Only in cart page (remove the line below to allow the display in checkout too)
    if( ! ( is_cart() || is_checkout() ) ) return $item_name;

    $product = $cart_item['data']; // Get the WC_Product object instance
    $shipping_class_id = $product->get_shipping_class_id(); // Shipping class ID
    $shipping_class_term = get_term( $shipping_class_id, 'product_shipping_class' );

    if( empty( $shipping_class_id ) )
        return $item_name; // Return default product title (in case of)

    $label = __( 'Shipping class', 'woocommerce' );

    return $item_name . '<br>
        <p class="item-shipping_class" style="margin:12px 0 0;">
            <strong>' .$label . ': </strong>' . $shipping_class_term->name . '</p>';
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.

經過測試并有效.

這篇關于在 WooCommerce 購物車頁面中的每個產品下方添加運輸類別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: www312aⅴ欧美在线看 | 日本欧美黄色片 | 欧美成人免费在线视频 | 国产精品久久久久久一区二区三区 | 午夜视频在线 | 中文在线一区二区 | 偷派自拍 | 国产成年人小视频 | 国产精品区二区三区日本 | 一本一道久久a久久精品综合蜜臀 | 精品久| 黄色一级大片在线免费看产 | 美国一级毛片a | jizz视频| av日韩高清 | 久久久久久久久综合 | 色必久久 | 久久国产电影 | 日韩美av | 精品免费国产视频 | 九九在线精品视频 | 一级黄色av电影 | 国产美女视频一区 | 伊人网综合 | 亚洲国产精品久久久 | 成人h动漫精品一区二区器材 | 久久99视频 | 成人一区二区三区视频 | 中文字幕第7页 | 日韩网站在线观看 | 中文字幕亚洲国产 | 久草新视频| 一级片av | 日韩免费 | 国产成人网| 黄色av一区 | 男人天堂视频在线观看 | 精品日韩一区 | 国产福利一区二区 | 黄色大片免费网站 | 人人澡视频 |