I need a better way to do this.
Currently, I have added code directly to the get_price_string function within class-wc-subscriptions-product.php file, so when a free
OK old question but I needed to do this recently. I didn't want to rely on string replacement so this is how I did it (can be adapted to suit your needs - they key is to look at the attributes in $product
which are available to you):
add_filter( 'woocommerce_subscriptions_product_price_string', 'my_subs_price_string', 10, 3 );
function my_subs_price_string( $subscription_string, $product, $include ) {
/****
var_dump($product); Various variables are available to us
****/
return 'An initial easy payment of ' . wc_price( $product->subscription_sign_up_fee ) .
', a ' . $product->subscription_trial_length . ' ' . $product->subscription_trial_period .
' trial of the product, then an outright purchase of ' . wc_price( $product->subscription_price );
}
Here is a VERY simple version for my site. I needed to have it say "per season" instead of "every 3 months". The simplest way was to create a plugin:
<?php
/**
* Plugin Name: My Subscription Price Text
* Description: Make it say "Every Season" instead of "Every 3 Months"
* Author: green coder
* Author URI:
* Version: 1.0
* License: GPL v2
*/
function my_subs_price_string( $pricestring ) {
$newprice = str_replace( 'every 3 months', 'per season', $pricestring );
return $newprice;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'my_subs_price_string' );
add_filter( 'woocommerce_subscription_price_string', 'my_subs_price_string' );
In /public_html/wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscriptions-product.php
Find get_price_string(...)
Adjust the Boolean values here:
$include = wp_parse_args( $include, array(
'tax_calculation' => get_option( 'woocommerce_tax_display_shop' ),
'subscription_price' => true,
'subscription_period' => true,
'subscription_length' => true,
'sign_up_fee' => true,
'trial_length' => true,
)
);