php - 如何在 woocommerce 订阅中更改多个订阅产品字符串?
问题描述
我的网站上有多个订阅产品,每月、每年和每周。
我正在运行此代码,它工作正常(将“月更改为 30 天”)但仅适用于具有“每月”的产品我如何应用它来更改每周和每年的字符串?
谢谢
function wc_subscriptions_custom_price_string( $pricestring ) {
$newprice = str_replace( 'month', '30 days', $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' );
解决方案
你可以选择替换所有你需要的字符串,只要你知道,它现在说什么。
我找不到文档,但考虑$pricestring
到 values biweekly
, weekly
, yearly
,我会遵循模式,并尝试:
function wc_subscriptions_custom_price_string( $pricestring ) {
$newprice = str_replace( 'biweekly', '14 days', $pricestring );
$newprice = str_replace( 'weekly', '7 days', $pricestring );
$newprice = str_replace( 'yearly', '365 days', $pricestring );
return $newprice;
}
基本上,它接受$pricestring
并替换里面找到的任何文本(第一个参数),并用任何文本(第二个参数)替换它,再次保存并返回修改后的$newprice
.
如果你biweekly
想避免在.weekly
weekly
biweekly
推荐阅读
- c# - EF 从同一张表中选择两次
- sql - MongoDB-esq SQL 查询
- asp.net - 如何在 Windows 2019 Server 上托管或运行旧版 ASP.NET 应用程序?
- python - Odoo 13 如何通过 api 运行动作?
- c# - 如何将图像或 html 代码存储在变量中?
- python - 使用 python 将 csv 文件从 GCS 存储桶上传到远程 sftp 位置
- python - 在json中保存对象
- node.js - Mongoose 添加异步虚拟字段
- python - Perlin 噪声问题:结果中的线条清晰可见
- sql - 如何使用 SQL 返回列表值