• Resolved dyin

    (@dyin)


    Hey,

    I would like to add a short line of text that only appears on the “my orders” page of the account dashboard (before the order history list).
    I have looked around for a solution but can’t find the correct code (snippet).
    This would come in very handy to give my customers instructions.

    Thanks for the help & all the best for 2022

    • This topic was modified 2 years, 11 months ago by dyin.
Viewing 5 replies - 1 through 5 (of 5 total)
  • You can either add custom code in 'myaccount/orders.php' template or you can use do_action( 'woocommerce_before_account_orders', $has_orders ); hook to add code before orders table.

    Thread Starter dyin

    (@dyin)

    @vijayhardaha Wow, thx far the fast reply!
    How would the code look like it I need to just have one line text using the hook?
    It should also be displayed it the customer doesn’t have any orders yet. My website uses this page often and people sometimes end up here even before they order.

    Edit: I always use the code snippets plugin as I avoid changing any templates.

    • This reply was modified 2 years, 11 months ago by dyin.
    /**
     * Display custom text before the account orders.
     *
     * @param bool $has_orders Having orders status.
     */
    function custom_wc_display_text_before_account_orders( $has_orders ) {
    	// If customer has orders then do nothing.
    	if ( $has_orders ) {
    		return;
    	}
    
        // Write your text if users don't have orders.
    	?>
    	<p>This is my text for the users who doesn't have orders yet.</p>
    	<?php
    }
    add_action( 'woocommerce_before_account_orders', 'custom_wc_display_text_before_account_orders', 10 );

    Something like this.

    Thread Starter dyin

    (@dyin)

    Thanks for the help!

    This is what worked (I made it WMPL compatible)

    add_action( 'woocommerce_before_account_orders', 'custom_wc_display_text_before_account_orders' );
    function custom_wc_display_text_before_account_orders( $has_orders ) {
    	if (ICL_LANGUAGE_CODE == 'nl')
    	{
    		echo '<p> my text NL</p>';
    	} else if (ICL_LANGUAGE_CODE == 'fr')
    	{
    		echo '<p> my text FR</p>'; 
    		
    	}       
    }
    
    Jay

    (@jaysonvos)

    @vijayhardaha How would the code look for customers who ‘do have orders’ in the order page? I require short text to be displayed above the orders in the my account order page for customers who have orders? Thanks so much

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding text on my orders page only (account dashboard)’ is closed to new replies.