3

I want to modify the subscription string so it only shows the sign-up fee for variations with 0$ recurring fee.

I would also like to show that variation price in the archive for that product rather than a price range.

I've tried using the str_replace function and it worked for everything besides this specific string. Besides, I am unable to select specifically the strings with 0$ recurring fees.

$subscription_string = str_replace('$0.00 / month and a ', '', $subscription_string)

The expected output would be only the signup price with the price string replaced with nothing

mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • It worked just fine for me - see [this screenshot](https://i.imgur.com/EpExIgz.png). Any chance your $subscription_string has capital letters in the text? str_replace is case sensitive by default. – Joshua T May 19 '19 at 11:04

1 Answers1

0

The variable $subscription_string will contain the HTML code for the currency amount and symbol. So the direct string replace will not work here with the text you provided.

add_filter('woocommerce_subscriptions_product_price_string', 'alter_woocommerce_subscriptions_product_price_string', 10, 3);

function alter_woocommerce_subscriptions_product_price_string($subscription_string, $product, $include) {
    if ($include['sign_up_fee']) {
        if (strpos($subscription_string, '0.00') !== false) {
            $subscription_string = explode('and a', $subscription_string);
            $subscription_string = $subscription_string[1];
        }
    }
    return $subscription_string;
}
mujuonly
  • 11,370
  • 5
  • 45
  • 75