3

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 trial is setup I can change the text being added to the price string.

This, of course, is far from perfect.

So, does anyone know what hook I need to add to the functions.php file in the theme's folder to be able to do the same thing?

mujuonly
  • 11,370
  • 5
  • 45
  • 75
Chunkford
  • 141
  • 1
  • 3
  • 13

3 Answers3

5

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 );
}
MrCarrot
  • 2,546
  • 1
  • 23
  • 29
3

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' );
raafi
  • 31
  • 1
  • Would the same be possible with other WooCommerce Subscriptions plugins, e.g. [Subscriptio](http://codecanyon.net/item/subscriptio-woocommerce-subscriptions/8754068)? – sPaul Sep 23 '14 at 13:20
-2

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,
    )
);
Ian
  • 27
  • 6