Home > Software design >  Add link to WooComerce my account page using hook
Add link to WooComerce my account page using hook

Time:07-09

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>';
};

CodePudding user response:

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
};

CodePudding user response:

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__.

  • Related