Modifying The WooCommerce Subscription Product Price Display
By default, the price display for a WooCommerce Subscription Product can be quite the mouthful (conceptually – more like a eyeful).
Anyway, it doesn’t do much to drive a point home, it’s not very concise.
I’ve found it’s much more effective to display the price only and handle the other caveats of the billing in other ways.
Here’s a screenshot of one of our subscription products as per WooCommerce’s default subscription price string.
And now it’s much cleaner after i’ve removed the sign up fee and trial length as below.
Now, it’s super simple to cut out elements of this string. There are multiple ways to do this, but the following is the most developer-friendly way of doing it.
First of all, you’re going to need to open functions.php, if you’re not sure how to do that you can check out our article about modifying functions.php here.
Now in essence, you can paste in the following code.
/**
*
* @author Christopher Davies
* @see class-wc-subscription-product.php
* @package WC
* @link https://wpdavies.dev/modify-woocommerce-subscription-price-display/
* @link https://wpdavies.dev/
* @snippet Modifying WooCommerce Subscription Product String
*
*/
add_filter( 'woocommerce_subscriptions_product_price_string_inclusions', 'wpd_override_subscription_price_string', 10, 2 );
function wpd_override_subscription_price_string( $include, $product ) {
/*
'tax_calculation' => get_option( 'woocommerce_tax_display_shop' ),
'subscription_price' => true,
'subscription_period' => true,
'subscription_length' => true,
'sign_up_fee' => true,
'trial_length' => true,
*/
$include['sign_up_fee'] = false;
$include['trial_length'] = false;
return $include;
}
Now in the above snippet, it will remove the sign up fee info and the trial length info.
Based on that you can kind of guess how it works, first of all i’ve commented out the other optional fields so they are not actively being filtered but you can see what’s there to choose from.
To remove or modify any one particular feature you just set it to true (examples include lines 25 and 26).
I’ll spell it out one by one just to make it crystal clear.
How To Remove The Trial Length From WooCommerce Subscription Product Price String
/**
*
* @author Christopher Davies
* @see class-wc-subscription-product.php
* @package WC
* @link https://wpdavies.dev/modify-woocommerce-subscription-price-display/
* @link https://wpdavies.dev/
* @snippet Modifying WooCommerce Subscription Product String
*
*/
add_filter( 'woocommerce_subscriptions_product_price_string_inclusions', 'wpd_override_subscription_price_string', 10, 2 );
function wpd_override_subscription_price_string( $include, $product ) {
$include['trial_length'] = false;
return $include;
}
How To Remove The Sign Up Fee From WooCommerce Subscription Product Price String
/**
*
* @author Christopher Davies
* @see class-wc-subscription-product.php
* @package WC
* @link https://wpdavies.dev/modify-woocommerce-subscription-price-display/
* @link https://wpdavies.dev/
* @snippet Modifying WooCommerce Subscription Product String
*
*/
add_filter( 'woocommerce_subscriptions_product_price_string_inclusions', 'wpd_override_subscription_price_string', 10, 2 );
function wpd_override_subscription_price_string( $include, $product ) {
$include['sign_up_fee'] = false;
return $include;
}
How To Remove The Subscription Length From WooCommerce Subscription Product Price String
/**
*
* @author Christopher Davies
* @see class-wc-subscription-product.php
* @package WC
* @link https://wpdavies.dev/modify-woocommerce-subscription-price-display/
* @link https://wpdavies.dev/
* @snippet Modifying WooCommerce Subscription Product String
*
*/
add_filter( 'woocommerce_subscriptions_product_price_string_inclusions', 'wpd_override_subscription_price_string', 10, 2 );
function wpd_override_subscription_price_string( $include, $product ) {
$include['subscription_length'] = false;
return $include;
}
We don’t use set subscription lengths so I don’t have a screenshot available, however this is the section that states the subscription goes for 3 months etc.
How To Remove The Subscription Period From WooCommerce Subscription Price String
/**
*
* @author Christopher Davies
* @see class-wc-subscription-product.php
* @package WC
* @link https://wpdavies.dev/modify-woocommerce-subscription-price-display/
* @link https://wpdavies.dev/
* @snippet Modifying WooCommerce Subscription Product String
*
*/
add_filter( 'woocommerce_subscriptions_product_price_string_inclusions', 'wpd_override_subscription_price_string', 10, 2 );
function wpd_override_subscription_price_string( $include, $product ) {
$include['subscription_period'] = false;
return $include;
}
How To Remove The Subscription Price From WooCommerce Subscription Price String
/**
*
* @author Christopher Davies
* @see class-wc-subscription-product.php
* @package WC
* @link https://wpdavies.dev/modify-woocommerce-subscription-price-display/
* @link https://wpdavies.dev/
* @snippet Modifying WooCommerce Subscription Product String
*
*/
add_filter( 'woocommerce_subscriptions_product_price_string_inclusions', 'wpd_override_subscription_price_string', 10, 2 );
function wpd_override_subscription_price_string( $include, $product ) {
$include['subscription_price'] = false;
return $include;
}
That's How We Edit The Subscription Product Price String
It’s all fairly straightforward, if i’ve left anything out don’t hesitate to let me know in the comments below and i’ll add it to this article.
There are other ways to take modifications further but I won’t touch on that for now – again just let me know below how I can help 🙂
Chris
Thank you so much for this – one thing that would be extra helpful
Can I change a text string?
change set-up fee to initial payment
Hi David,
Yep you could use a string replace function, this is the snippet i’d use – haven’t tested it though.
You would need to make sure that whatever’s currently showing is exactly what is assigned to the $curren_string variable, it’s searching for that and will then replace with $new_string.
add_filter( ‘woocommerce_subscriptions_product_price_string’, ‘wpd_change_subscription_product_string’, 10, 3 );
function wpd_change_subscription_product_string( $subscription_string, $product, $include ) {
if ( $include[‘sign_up_fee’] ){
$current_string = ‘sign-up fee’;
$new_string = ‘Initial Payment’;
$subscription_string = str_replace($current_string, $new_string, $subscription_string);
}
return $subscription_string;
}
This is super helpful! Can you tell me how to remove, or change out the text after a one time sign-up fee that says, “one time, and” because I can’t seem to get rid of it. I’m poking around in the WooCommerce Subscriptions plugin trying to find it, but I’m not much of a programmer.