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.
/** * * @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; }
/** * * @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; }
/** * * @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.
/** * * @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; }
/** * * @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; }
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
Supercharge your WooCommerce store with WP Davies
Copyright © 2021 Design by WP Davies