Customize the Thank you message with WooCommerce Subscriptions

,

Using WooCommerce Subscriptions you get a “Thank you” message after purchasing a subscription product which says:

Your subscription will be activated when payment clears. View the status of your subscription in your account.

Do you know that you can change this text to the that best matches your style/site?

To do so, open the file functions.php located in wp-content/themes/your-theme-name/ and add this code at the end of it:


/**
* Change the subscription thank you message after purchase
*
* @param int $order_id
* @return string
*/
function custom_subscription_thank_you( $order_id ){
if( WC_Subscriptions_Order::order_contains_subscription( $order_id ) ) {
$thank_you_message = sprintf( __( '%sThank you for purchasign our subscription! Visit %syour account%s page to know its status.%s', 'woocommerce-subscriptions' ), '<p>', '<a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">', '</a>','</p>' );
return $thank_you_message;
}
}
add_filter( 'woocommerce_subscriptions_thank_you_message', 'custom_subscription_thank_you');

view raw

functions.php

hosted with ❤ by GitHub

9 replies
  1. simi
    simi says:

    Hi,

    Tried to add this to my functions.php file, right at the bottom – however this was the result after I copied the code to the file – the page said:

    Parse error: syntax error, unexpected end of file in /home//public_html//wp-content/themes/***/functions.php on line 963

    ( * = hidden from public)

    Please advise on solution.

    [I have latest WP & WooSubscription 2.0.5]

    Regards.

    Reply
  2. Simi
    Simi says:

    FOUND SOLUTION :

    wp-content/plugins/Subscriptionsv2.0.5/includes/class-wc-subscriptions-order.php

    Press Command/Control F on your keyboard and search : ‘Your subscription’ – and you’re able to rename :

    ‘Your subscription will be activated when payment clears. View the status of your subscription in your account’.

    Reply
  3. flo_itvolcano
    flo_itvolcano says:

    simi, that’s not a sollution because it’ll be overwritten on next plugin update.

    the code above (besides a typo) has an error. it is missing ; at the end of add_filter( ‘woocommerce_subscriptions_thank_you_message’, ‘custom_subscription_thank_you’)

    So it should be add_filter( ‘woocommerce_subscriptions_thank_you_message’, ‘custom_subscription_thank_you’); instead

    Reply
  4. Aron
    Aron says:

    Hey Nicola,

    Great blog, I’ve actually landed on your site a few times now with my searches and have used a few of your scripts already, however this one doesnt seem to be working for me. Initially, it was simply throwing me an error, so I added the semi-colon at the very end and cleared the error, however now it has simply removed the default message (“Your subscription will be activated when payment clears. View the status of your subscription in your account.”) altogether.

    I would really like to resolve this if you have any ideas for me. Thanks in advance!

    Reply
  5. Drew
    Drew says:

    This code just needs a simicolon at the end, thats the only problem. The line:

    add_filter( ‘woocommerce_subscriptions_thank_you_message’, ‘custom_subscription_thank_you’)

    Should be:

    add_filter( ‘woocommerce_subscriptions_thank_you_message’, ‘custom_subscription_thank_you’);

    Reply
  6. katmacaus
    katmacaus says:

    Thanks. A note that this function has now deprecated. Need to replace ‘WC_Subscriptions_Order::order_contains_subscription( $order_id )’ with:

    wcs_order_contains_subscription( $order_id )

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply