2

The first part of the question (Hide the “free trial” text from Woocommerce Subscriptions price) was answered in this awesome post:

Hide the "free trial" text from Woocommerce Subscriptions price

However, it removed the "and a xx sign-up fee". Is there any way to keep the sign up fee text after removing the free trial text?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Arvy S.
  • 45
  • 1
  • 6

2 Answers2

3

Updated - Try the following:

add_filter( 'woocommerce_subscriptions_product_price_string', 'subscriptions_custom_price_string', 20, 3 );
function subscriptions_custom_price_string( $price_string, $product, $args ) {
    // Get the trial length to check if it's enabled
    $trial_length  = $product->get_meta('_subscription_trial_length');
    $subscr_period = $product->get_meta('_subscription_period');
    $subscr_fee    = wc_price( $product->get_meta('_subscription_sign_up_fee') );

    $sign_up_fee = isset($args['sign_up_fee']) ? __(" and a $subscr_fee sign-up fee", "woocommerce") : '';
    if( $trial_length > 0 )
        $price_string = $args['price'] . ' / ' . $subscr_period . $sign_up_fee;

    return $price_string;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • @LoicTheAziec seems like only you can help me with this https://stackoverflow.com/questions/68311716/wordpress-woocommerce-get-sign-up-fee-based-on-available-variations I have put my every effort so far and I am pretty close. Can you please help me from here on. Any help or support or guidance will be highly appreciated. Thank in advance. – Mittul At TechnoBrave Jul 12 '21 at 12:03
  • How can we hide *just* the "free trial" text while keeping the first part of the string "every X weeks on Thursday"? – armadadrive Jul 23 '21 at 15:00
0

Searched the same function, found a good solution:

add_filter( 'woocommerce_subscriptions_product_price_string_inclusions', function ( $include ) {
    $include['trial_length'] = false;

    return $include;
} );
endcoreCL
  • 29
  • 1
  • 6
  • Code without any explanation are rarely helpful. Stack Overflow is about learning, not providing snippets to blindly copy and paste. Please edit your question and explain how it answers the specific question being asked. See [How to Answer](https://stackoverflow.com/help/how-to-answer). – Sfili_81 Dec 10 '21 at 11:20