【问题标题】:Woocommerce How to replace the sale price of out of stock products but keep the Regular price? [closed]Woocommerce 如何替换缺货产品的销售价格但保持正常价格? [关闭]
【发布时间】:2021-09-24 18:25:32
【问题描述】:

我不擅长代码,我被困在这种情况下。我们的产品有 2 个价格:

  • 零售价
  • 折扣价。

我想用“SOLD OUT”文本替换“缺货”产品的促销价,并仍然保留零售价,同时删除产品图片上的“销售百分比”徽章。

我正在使用 Replace displayed price by a text for out of stock WooCommerce products 答案代码,效果很好,但它将所有价格替换为已售文本,​​我不知道如何根据需要对其进行编码。

【问题讨论】:

标签: php wordpress woocommerce product


【解决方案1】:
add_filter('woocommerce_get_price_html', 'change_sold_out_product_price_html', 100, 2 );
function change_sold_out_product_price_html( $price_html, $product ) {
    if ( ! $product->is_in_stock() ) {
        $regular_price = wc_price($product->get_regular_price());
        $price_html = __($regular_price."SOLD", "woocommerce");
    }
    return $price_html;
}

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
  • 感谢您的代码。该代码有效,但货币仍然存在,我该如何删除它?谢谢
  • 我使用来自@LoicTheAztec 的这段代码,它删除了货币符号。谢谢code add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);函数 change_existing_currency_symbol( $currency_symbol, $currency ) { $product = wc_get_product( get_the_ID() ); if ( is_a( $product, 'WC_Product' ) && $currency === 'USD' && ! $product->is_in_stock() ) { $currency_symbol = ''; } 返回 $currency_symbol; } code
  • 请替换 $regular_price = wc_price($product->get_regular_price());到 $regular_price =$product->get_regular_price();
  • 如果我替换上面给出的代码,正常价格将以数字形式返回,并且每个 3 个数字没有千位分隔符,例如 $1,000,000 将是 1000000。我使用我添加的第二个代码和它将删除销售价格中的货币符号(缺货产品)。您能帮我添加 常规价格 来设置此常规价格文本的样式和 SOLD 文本的类吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-15
  • 1970-01-01
  • 2020-08-21
  • 2021-05-03
相关资源
最近更新 更多