You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用printf函数生成含WooCommerce变量的HTML链接?

Looks like you’ve got the right core idea using printf to build your order link, but the issue is you’re passing the static string 'woocommerce' to the first %s placeholder instead of the actual order number. That’s why your link is landing on /view-order/woocommerce/ instead of the correct order-specific page.

Here’s the corrected code that replaces both %s placeholders with the dynamic order number:

<?php 
printf(
    '<a href="https://www.baseclothing.nl/mijn-account/view-order/%s/">https://www.baseclothing.nl/mijn-account/view-order/%s/</a>',
    esc_html( $order->get_order_number() ),
    esc_html( $order->get_order_number() )
); 
?>

Key Fixes Explained:

  • Removed the static 'woocommerce' string and replaced it with esc_html( $order->get_order_number() ) for the first placeholder. Now both the link’s href attribute and the visible text will use the actual order number from your $order object.
  • We keep using esc_html() to sanitize the order number—this is a critical best practice to prevent potential XSS vulnerabilities in your output.

Just double-check that the $order variable is a valid WooCommerce Order object when this code runs (for example, that it’s being used in a context where the order is properly initialized, like on an order confirmation page or customer email template).

内容的提问来源于stack exchange,提问作者Rick van Baalen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:25:43