【问题标题】:Change the entire product string in WooCommerce Subscripitons更改 WooCommerce 订阅中的整个产品字符串
【发布时间】:2018-11-09 03:30:28
【问题描述】:

我想更改 WooCommerce 订阅中价格字符串的文本和顺序。现在它说:

“每月 1 日 35.00 美元,为期 11 个月,注册费 35.00 美元。”

我想让它说:

“第一个盒子 35.00 美元,然后每月 1 日 35.00 美元,持续 11 个月。”

我找到了可以用来将“注册费”更改为“第一个盒子”的代码:

 /* WooCommerce Subscriptions Price String */

 function wc_subscriptions_custom_price_string( $pricestring ) {
    $newprice = str_replace( 'sign-up fee', 'for the first box', $pricestring );
    return $newprice;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );
add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string' );

现在它说 “11 个月内每月 1 日 35.00 美元,第一个盒子 35.00 美元。”

如何更改订单?

【问题讨论】:

  • 所有订阅的价格都一样吗?
  • 目前只有一个订阅,但未来可能会更多。

标签: wordpress woocommerce woocommerce-subscriptions


【解决方案1】:

只需将原始字符串分解为数组即可重新排序:

function wc_subscriptions_custom_price_string( $pricestring ) {
   $replace_price = str_replace( 'sign-up fee', 'for the first box', $pricestring );
   $aPrice = explode(" and a ", $replace_price);
   $newprice = $aPrice[1] . " and then " . $aPrice[0]; 
   $finalprice = str_replace(" on "," +shipping on ", $newprice);
   return finalprice;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );
add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string' );

见:explode()

或者如果你想变得花哨:

$newprice = implode(" and then ", array_reverse($aPrice));

【讨论】:

  • 好的,这很好,但在与客户交谈后我有了些许改变。他们希望它说“第一个盒子 35.00 美元,然后每月 1 日 35.00 美元+运费,为期 11 个月。
  • 我们怎样才能在价格和“每 1 日...”之间添加“+运费”?
猜你喜欢
  • 1970-01-01
  • 2018-06-17
  • 2018-08-31
  • 2017-06-18
  • 1970-01-01
  • 2014-02-02
  • 2021-01-25
  • 2017-12-03
  • 2019-07-29
相关资源
最近更新 更多