Customizing the subscription price string

If you're running a subscription site, there are bound to be things you want to customize to make your website reflect your brand. Subscriptions are loaded with hooks that developers can use to customize all sorts of things programmatically. We'll be manipulating the Subscriptions price string using a filter just to show how things are done.

Getting ready

You must have the WooCommerce Subscriptions plugin installed and activated on your site.

How to do it…

In order to customize the subscription price string, go through the following steps:

  1. Open up your theme's functions.php file, located under wp-content/themes/your-theme-name/, or create a custom WooCommerce plugin and open up that file.
  2. Add the following two lines of code. These tell Subscriptions to look for your modifications to the price string:
    add_filter( 'woocommerce_subscriptions_price_string', 'woocommerce_cookbook_subscription_price_string', 10, 2 );
    add_filter('woocommerce_subscriptions_product_price_string' , 'woocommerce_cookbook_subscription_price_string', 10, 2 );

    Now we need to write the modifications. Add the following code:

    function woocommerce_cookbook_subscription_price_string( $subscription_string, $product ) { 
        $subscription_string = $subscription_string . '. In 2016 all subscriptions will get a price increase. Buy now to be grandfathered in.'; 
        return $subscription_string; 
    }
  3. Save and upload the file to your site.

    Look at your subscription on the frontend and you can see the addition we made to the price string.

    How to do it…

There's more...

There are dozens of filters you can use to modify all sorts of things in Subscriptions. If you're a developer, you can read through the developer docs at http://docs.woothemes.com/document/subscriptions/develop/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset