使用挂钩将链接添加到WooComceer

发布于 2025-02-13 22:33:09 字数 571 浏览 1 评论 0原文

我从@loictheaztec中找到了此代码,可添加,允许您在Woocomceers中的“我的帐户-Dashboard”选项卡中添加一些额外的文本。

我正在尝试添加一个超级链接,但是我的php知识和语法令人震惊,显然我无法使用标准a href html来执行此操作:语法错误:意外的标识符“ https” “,期望”)”

关于如何添加URL的任何帮助,将不胜感激。谢谢。

代码 :

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

零崎曲识 2025-02-20 22:33:09

您使用的是两次取消彼此的双引号。更简单的方法。另外,您需要将翻译功能与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
};

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
};
楠木可依 2025-02-20 22:33:09
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>';
}

总是 secave/secure Output 用于使用类似ESC_HTML _____html ___ 。

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

半葬歌 2025-02-20 22:33:09

在马丁的帮助下解决了这个问题。也感谢所有其他建议。

我最终这样做的方式是使用建议的仪表板钩子和单引号回声。

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

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>';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文