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

在產品打折時為價格??添加自定義文本標簽

Adding custom text labels to the prices when products are on sale(在產品打折時為價格??添加自定義文本標簽)
本文介紹了在產品打折時為價格??添加自定義文本標簽的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在 WooCommerce 產品單頁上,如果產品具有銷售價格,則將正常價格劃掉,并在其后面突出顯示銷售價格.

我的問題:
如何添加舊價格:XX美元"新價格:XX美元"等標簽而不是只有劃掉的和新的價格(銷售價格)?

解決方案

更新 2(針對簡單和可變的產品 + 解決了相同變體價格的錯誤)

當產品打折時,您可以使用掛接在 woocommerce_sale_price_htmlwoocommerce_variation_sale_price_html 過濾器鉤子(用于簡單和可變的產品.

對于變量產品的最低/最高價格,我們需要在 woocommerce_variation_sale_price_html 過濾器鉤子中掛鉤不同的函數.

代碼如下:

add_filter('woocommerce_variation_sale_price_html','sale_prices_custom_labels', 10, 2 );add_filter('woocommerce_sale_price_html','sale_prices_custom_labels', 10, 2);函數 sale_prices_custom_labels( $price, $product ){如果 (isset($product->sale_price)) {$price = ''.__('舊價格:', 'woocommerce') .woocommerce_price( $product->regular_price ).'</del><ins class="highlight">'.__('新價格:', 'woocommerce') .woocommerce_price( $product->sale_price ) .'</ins>';}別的{$price = '<ins class="highlight">'.woocommerce_price( $product->regular_price ).'</ins>';}返回 $price;}add_filter('woocommerce_variable_sale_price_html', 'sale_prices_custom_labels_min_max', 20, 2);函數 sale_prices_custom_labels_min_max( $price, $product) {$variation_min_reg_price = $product->get_variation_regular_price('min', true);$variation_max_reg_price = $product->get_variation_regular_price('max', true);$variation_min_sale_price = $product->get_variation_sale_price('min', true);$variation_max_sale_price = $product->get_variation_sale_price('max', true);如果 ( $variation_min_reg_price != $variation_min_sale_price || $variation_max_reg_price != $variation_max_sale_price ){if($variation_min_reg_price == $variation_max_reg_price && $variation_min_sale_price == $variation_max_sale_price ){$price = ''.__('舊價格:', 'woocommerce') .woocommerce_price($variation_max_reg_price) .'</del><ins class="highlight">'.__('新價格:', 'woocommerce') .woocommerce_price($variation_max_sale_price) .'</ins>';}elseif($variation_min_reg_price != $variation_max_reg_price && $variation_min_sale_price == $variation_max_sale_price ){$price = ''.__('舊價格:', 'woocommerce') .woocommerce_price($variation_min_reg_price) .'-' .woocommerce_price($variation_max_reg_price) .'</del><ins class="highlight">'.__('新價格:', 'woocommerce') .woocommerce_price($variation_max_sale_price) .'</ins>';}elseif($variation_min_reg_price == $variation_max_reg_price && $variation_min_sale_price != $variation_max_sale_price ){$price = ''.__('舊價格:', 'woocommerce') .woocommerce_price($variation_max_reg_price) .'</del><ins class="highlight">'.__('新價格:', 'woocommerce') .woocommerce_price($variation_min_sale_price) .'-' .woocommerce_price($variation_max_sale_price) .'</ins>';}別的{$price = ''.__('舊價格:', 'woocommerce') .woocommerce_price($variation_min_reg_price) .'-' .woocommerce_price($variation_max_reg_price) .'</del><ins class="highlight">'.__('新價格:', 'woocommerce') .woocommerce_price($variation_min_sale_price) .'-' .woocommerce_price($variation_max_sale_price) .'</ins>';}}返回 $price;}

<塊引用>

你也可以用一些東西替換普通的 html 標簽else 并更改或添加一些類(如果對您更方便的話).此時一切皆有可能.

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

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

<小時>

相關答案:條件定制圍繞產品銷售價格和正常價格的輸出

On WooCommerce product single pages, if a product owns a sales price, the normal price is crossed out and behind it, the sale price is highlighted.

My question:
How can I add a label like "Old Price: XX Dollar" and "New Price: XX Dollar" instead of only the crossed out and the new price (sale price)?

解決方案

Update 2 (for simple and variable products + solved the bug on same variations prices)

when products are on sale, you can add custom labels just as you want using a custom function hooked in woocommerce_sale_price_html and woocommerce_variation_sale_price_html filters hooks (for simple and variables products.

For the min / max prices in variables products, we need a different function hooked in woocommerce_variation_sale_price_html filter hook.

Here is that code:

add_filter('woocommerce_variation_sale_price_html','sale_prices_custom_labels', 10, 2 );
add_filter('woocommerce_sale_price_html','sale_prices_custom_labels', 10, 2 );
function sale_prices_custom_labels( $price, $product ){
    if (isset($product->sale_price)) {
        $price = '<del class="strike">' . __('Old Price: ', 'woocommerce' ) . woocommerce_price( $product->regular_price ). '</del>
        <ins class="highlight">' . __('New Price: ', 'woocommerce' ) . woocommerce_price( $product->sale_price ) . '</ins>';
    }
    else
    {
        $price = '<ins class="highlight">'.woocommerce_price( $product->regular_price ).'</ins>';
    }
    return $price;
}

add_filter('woocommerce_variable_sale_price_html', 'sale_prices_custom_labels_min_max', 20, 2);
function sale_prices_custom_labels_min_max( $price, $product) {

    $variation_min_reg_price = $product->get_variation_regular_price('min', true);
    $variation_max_reg_price = $product->get_variation_regular_price('max', true);
    $variation_min_sale_price = $product->get_variation_sale_price('min', true);
    $variation_max_sale_price = $product->get_variation_sale_price('max', true);

    if ( $variation_min_reg_price != $variation_min_sale_price || $variation_max_reg_price != $variation_max_sale_price )
    {
        if($variation_min_reg_price == $variation_max_reg_price && $variation_min_sale_price == $variation_max_sale_price ){
            $price = '<del class="strike">' . __('Old Price: ', 'woocommerce' ) . woocommerce_price($variation_max_reg_price) . '</del>
            <ins class="highlight">' . __('New Price: ', 'woocommerce' ) . woocommerce_price($variation_max_sale_price) . '</ins>';
        }
        elseif($variation_min_reg_price != $variation_max_reg_price && $variation_min_sale_price == $variation_max_sale_price )
        {
            $price = '<del class="strike">' . __('Old Price: ', 'woocommerce' ) . woocommerce_price($variation_min_reg_price) . '-' . woocommerce_price($variation_max_reg_price) . '</del>
            <ins class="highlight">' . __('New Price: ', 'woocommerce' ) . woocommerce_price($variation_max_sale_price) . '</ins>';
        }
        elseif($variation_min_reg_price == $variation_max_reg_price && $variation_min_sale_price != $variation_max_sale_price )
        {
            $price = '<del class="strike">' . __('Old Price: ', 'woocommerce' ) . woocommerce_price($variation_max_reg_price) . '</del>
            <ins class="highlight">' . __('New Price: ', 'woocommerce' ) . woocommerce_price($variation_min_sale_price) . '-' . woocommerce_price($variation_max_sale_price) . '</ins>';
        }
        else
        {
        $price = '<del class="strike">' . __('Old Price: ', 'woocommerce' ) . woocommerce_price($variation_min_reg_price) . '-' . woocommerce_price($variation_max_reg_price) . '</del>
        <ins class="highlight">' . __('New Price: ', 'woocommerce' ) . woocommerce_price($variation_min_sale_price) . '-' . woocommerce_price($variation_max_sale_price) . '</ins>';
        }
    }
    return $price;
}

You can also replace the normal <ins> and <del> html tags by something else and change or add some classes too (if is more convenient for you). At this point everithing is possible.

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works.


Related answers: Conditional custom output around products sale price and regular price

這篇關于在產品打折時為價格??添加自定義文本標簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 字節))
主站蜘蛛池模板: 欧美阿v | 久久99精品久久久久久青青日本 | 日韩精品av一区二区三区 | 福利社午夜影院 | 亚洲欧美日韩在线不卡 | 成人精品视频在线观看 | 国产日韩精品一区 | 日韩欧美一区二区三区免费观看 | 亚洲综合在线视频 | 欧美精品一区二区三区在线 | 国产精品久久久久久av公交车 | 国产一级在线观看 | 亚洲国产小视频 | 成人久久18免费网站图片 | 国产精品一区在线 | 亚洲国产福利视频 | 国产精品美女久久久久久免费 | 欧美日韩中文字幕 | 久久久视 | 国产高清视频一区 | 91美女在线观看 | 日韩av一区二区在线观看 | 97久久精品午夜一区二区 | 免费看爱爱视频 | 91传媒在线观看 | 亚洲精品一区二区三区 | 中文字幕一区二区在线观看 | 人人做人人澡人人爽欧美 | 国产视频91在线 | 欧美在线成人影院 | 综合精品在线 | 日本免费在线 | 国产在线精品一区二区 | 亚洲国产精品日本 | 国产精品久久久久无码av | 精品综合 | 亚洲第一中文字幕 | 久久免费视频1 | 欧美中文字幕一区 | 一区二区三区在线观看视频 | 中文在线一区二区 |