本篇文章更新時間:2020/10/17
如有資訊過時或語誤之處,歡迎使用 Contact 功能通知。
一介資男的 LINE 社群開站囉!歡迎入群聊聊~
如果本站內容對你有幫助,歡迎使用 BFX Pay 加密貨幣新台幣 贊助支持。


亂逛看到的功能,頗簡單又實用!

於(子)主題裡的 functions.php 檔案中加入下方程式碼片段(或可以使用 Code Snippets 這隻外掛來處理。):

function mxp_custom_sale_flash($text, $post, $product) {
    global $product;
    $percentage = round((($product->regular_price - $product->sale_price) / $product->regular_price) * 100);
    return '' . $percentage . '%';
}

add_filter('woocommerce_sale_flash', 'mxp_custom_sale_flash', 10, 3);

就能在特價商品的標籤上顯示這個折扣的百分比了!

折扣百分比

至於還想要改成其他種顯示做法也是直接從上面的程式碼範例去下手調整。

Ref: How can I change woocommerce_sale_flash from Text to Discount Percentage


Share:

作者: Chun

資訊愛好人士。主張「人人都該為了偷懶而進步」。期許自己成為斜槓到變進度條 100% 的年輕人。[///////////____36%_________]

參與討論

  1. nn4work
  2. Chun

2 則留言

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *


文章
Filter
Apply Filters
Mastodon