I have multiple subscription products in my website with monthly, yearly and weekly.
I am running this code which is working fine (changing “month to 30 days “) but only works for the products with “Monthly” how can I apply it to change the the string for weekly and yearly also?
Thank you
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' );
2
Answers
You can choose to replace all strings you need given that you know, what it says right now.
I can’t find the documentation, but given that the
$pricestring
takes on valuesbiweekly
,weekly
,yearly
, I would follow the pattern, and try:Basically, it takes the
$pricestring
and replaces whatever the text (the first parameter) found inside, and replaces it with whatever text (the second parameter), saving it again and returning the modified$newprice
.Notice the order of
biweekly
andweekly
if you want to avoid accidentally rewritingweekly
inbiweekly
.Just do similar replaces, you can even embed them, like: