【问题标题】:Woocommerce custom price after actual price实际价格后的 Woocommerce 自定义价格
【发布时间】:2023-01-11 03:58:13
【问题描述】:

我正在寻找可以帮助我为我的 woocommerce(7.2.2 版)商店产品添加自定义价格的功能。 (仅作为前端的文本)。我已经在使用 yith 会员资格为我的客户提供折扣,但我无法在用户购买会员资格之前显示折扣价格。

例子:

我的价格是 2 美元,我想在价格后添加以下文本:1 美元,订阅 x。

演示:

  Product title
         2$
1$ with subscription x

该函数需要使用以下固定折扣计算订阅 x 的价格

original price - 50% = subscription price

如果产品已经有折扣,这也需​​要有一些条件。

    Product title
  <del>2$</del> 1.8$
0,9$ with subscription x

我尝试了一些允许我添加一些文本作为当前价格后缀的模块,但无法使用这些模块计算自定义价格。

【问题讨论】:

    标签: woocommerce


    【解决方案1】:

    最终解决方案:我添加了 25% 的折扣 + 自定义文本

    function wptips_custom_html_addon_to_price(  $price, $product ) {
    
     $pretinitial = $price;
    $sale_price = $product->sale_price;
    
    if (!empty($sale_price)) {
        $pretfinalscos = $sale_price;
    }
    else 
    {
        $pretfinalscos = $pretinitial;
    }
    
       $pretfinal = preg_replace("/[^0-9,.]/", "", "$pretfinalscos");
            $pretfinal = str_replace(',', '.', $pretfinal);
             $pricegold = $pretfinal - ($pretfinal * (25 / 100));
    
     $html_price_suffix = '<span style="color:black;" class="price-suffix"> <br>Cu abonamentul Gold '.number_format((float)$pricegold, 2, '.', '').' lei</span>'; // custom suffix html that you want to add after price
    
     if ( !empty( $price ) ) {
         $price = $html_price_prefix . ' ' . $price . ' ' . $html_price_suffix;
          return $price;
        } else {
          return $price;
        }
    }
    add_filter( 'woocommerce_get_price_html', 'wptips_custom_html_addon_to_price', 999, 2 );
    add_filter( 'woocommerce_cart_item_price', 'wptips_custom_html_addon_to_price', 999, 2 );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 2023-03-31
      • 2021-04-29
      • 2014-03-11
      • 2021-02-04
      • 2015-11-28
      相关资源
      最近更新 更多