Support » Plugin: WooCommerce » Want to modify thank you page with custom message

  • Resolved David Borrink

    (@davidborrink)


    I’m trying to add an additional message to a thank you page after a purchase.

    I have a thankyou.php page in my child theme in a woocommerce folder. I’ve read that template changes in a child theme need to go in a woocommerce folder in my child theme.

    I edit the thankyou.php file and uploade, but no change is showing up when I test a purchase. To verify that I’m working with the correct file, I changed the text below to have an exclamation mark at the end of the text. But when I tested it there is no change.

    <p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received!', 'woocommerce' ), $order ); ?></p>

    What I want to do is add a function that will add a message with some links to social media buttons.

    This is the function code I want to place in the thankyou.php file:

    <p><?php thank_you_links(); ?>
    </p>

    And this is my function for the function.php file…

    function thank_you_links() {
    	?>
    Sign up for our <a href="http://domain.com/newsletter" target="_blank">newsletter!</a><br/><br/>
    Join the conversation with other teachers! Check us out on social media at: <a href="https://www.facebook.com/company-name" target="_blank">Facebook</a>, <a href="https://twitter.com/company-name" target="_blank">Twitter</a>, and <a href="https://plus.google.com/u/0/+company-name/posts" target="_blank">Google Plus</a>!

    I just need to verify the placement location.

    https://wordpress.org/plugins/woocommerce/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Consider doing this task with a hook. The code goes in functions.php for child theme.

    <?php
      add_action ('woocommerce_thankyou', 'myfunction');
      function myfunction($order_id) {
        echo 'My message';
      }

    If this does what you want, you can leave thankyou.php alone so it can be updated by WooCommerce if necessary.

    Oh excellent. That’s a much better way. Problem solved.

    Thank you!

    Lorro,
    Thank-you for this tip. But I need just a bit more explanation as to how this hook works. What is $order_id and how id this useful? I assume that “My message” is what you want to add to the thank-you page.
    It seems as though this is exactly what I need to add to my functions.php page but I just need a little explanation as to how it works.
    All I want to do is to add a message that says “If you are satisfied with your purchase, please consider leaving a Review on the product page. We appreciate your support!”
    Thank-you so much

    I played around with your code snippet you provided (thank-you again by the way) and I noticed that “my message” appeared on my thank-you page but actually kind of buried in the middle of the page and it was hard to see.
    Is this where the $order_id variable comes in? Is that what tells the page WHERE to put the message? If so, how do I know what each number each section of the page is?
    The first line of the Thank-you page says “Thank you. Your order has been received.” Right after this, I would like to give my message. How can I specify to put that message up there? Also, is it possible to make it bold or a different color directly from this snippet?
    This has been very helpful. It is these kinds of tips that help us beginners become more knowledgeable.

    The $order_id value is passed to the function automatically. You don’t have to make use of it if you don’t need it.

    $order_id does not control message placement.

    The line:

    add_action ('woocommerce_thankyou', 'myfunction', 30);

    can optionally take a priority parameter, 30 in this example. A lower number = higher priority(!) so the function fires sooner. If you get the priority down to 1 and the message is not appearing in the required place, you need a different hook.
    https://docs.woothemes.com/wc-apidocs/hook-docs.html

    To change color or font weight, use something like:

    print '<p class="important_message">My message</p>';

    then in custom css use:

    .important_message {color:red; font_weight:700}

    Lorro, very cool. I changed the priority gradually until I got it to where I want it, which in this case is “5”.
    However, the statement:
    print ‘<p class=”important_message”>My message</p>’; simply put “my message”
    as the first line on the page. Should it have been “myfunction” so that I can
    control the color and weight of the message with the css?

    Yes, the print goes inside the function:

    <?php
      add_action ('woocommerce_thankyou', 'myfunction');
      function myfunction($order_id) {
        print '<p class="important_message">My message</p>';
      }

    That’s it precisely. Thanks so much for your help!
    John

    IMHO…I believe the correct way to do this would be to filter the message by WC as such:

    add_filter( 'woocommerce_thankyou_order_received_text', 'd4tw_custom_ty_msg' );
    
    function d4tw_custom_ty_msg ( $thank_you_msg ) {
    $thank_you_msg =  'This is your new thank you message';
        return $thank_you_msg;
    }
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Want to modify thank you page with custom message’ is closed to new replies.