skip to Main Content

I found this code from @LoicTheAztec that adds allows you to add some extra text to the My Account – Dashboard tab in WooComerce.

I am trying to add a hyper link to it however my php knowledge and syntax is appalling and I clearly can’t use the standard a href html to do this as this throws an error : syntax error, the unexpected identifier "https", expecting ")"

Any help on how I could add a URL to this would be very much appreciated. Thank you.

Code :

add_action( 'woocommerce_account_content', 'action_woocommerce_account_content' );
function action_woocommerce_account_content(  ) {
    global $current_user; // The WP_User Object

    echo '<p>' . __("<a href="https://google.com"> Request Wholesale account </a>", "woocommerce") . '</p>';
};

3

Answers


  1. Chosen as BEST ANSWER

    Solved this with Martin's help. Thanks for all the other suggestions too.

    The way I ended up doing it was to use the Dashboard hook as suggested and the single quote echo.

    add_action( 'woocommerce_account_dashboard', 'custom_account_dashboard_content' );
    function custom_account_dashboard_content(){
        echo '<div>' . __('<br><b><a href="https://google.com"> REQUEST WHOLESALE ACCOUNT </a></b>', 'woocommerce') . '</div>';
    }
    

  2. You are using double quotes twice which cancel each others. simpler way to do it. also you need to separate the translation function from the html.

        add_action( 'woocommerce_account_content', 'action_woocommerce_account_content' );
        function action_woocommerce_account_content() {
            global $current_user; // The WP_User Object
            ?>
            <p><a href="https://google.com"><?php _e( 'Request Wholesale account', 'woocommerce' ); ?></a></p>
            <?php
    };
    
    Login or Signup to reply.
  3. add_action('woocommerce_account_content', 'action_woocommerce_account_content');
    
    function action_woocommerce_account_content() {
        global $current_user; // The WP_User Object
    
        echo '<p>' . sprintf(esc_html__('%1$s Request Wholesale account %2$s', 'woocommerce'), '<a href="https://google.com">', '</a>') . '</p>';
    }
    

    Always escape/secure output for security using like esc_html__.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search