WooCommerce 在处理订单电子邮件中添加产品链接

Soh*_*aib 6 wordpress woocommerce

我想在用户订购时收到的处理订单电子邮件中添加产品链接。当下订单时发送订单电子邮件,我想在用户单击时获得产品链接,单击时重定向到详细产品页面。有什么办法,我得到产品链接或产品标题将超链接。

谢谢

Jar*_*rom 7

来自 gunbunnysoulja 的答案效果很好,但需要两个小更新:

  • get_product 需要是 wc_get_product
  • $_product->id 需要是 $_product->get_id()

更新后的答案如下:

add_filter( 'woocommerce_order_item_name', 'display_product_title_as_link', 10, 2 );
function display_product_title_as_link( $item_name, $item ) {

    $_product = wc_get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );

    $link = get_permalink( $_product->get_id() );

    return '<a href="'. $link .'"  rel="nofollow">'. $item_name .'</a>';
}
Run Code Online (Sandbox Code Playgroud)

  • 这就像一个魅力!非常感谢您花时间参与并分享这个! (2认同)

小智 5

我目前正在使用这个解决方案,我在另一页的评论中找到了它。这不是我的代码。

http://www.vanbodevelops.com/tutorials/add-a-link-back-to-the-order-in-woocommerce-new-order-notifications-email#comment-636

add_filter( 'woocommerce_order_item_name', 'display_product_title_as_link', 10, 2 );
function display_product_title_as_link( $item_name, $item ) {

$_product = get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );

$link = get_permalink( $_product->id );

return '<a href="'. $link .'"  rel="nofollow">'. $item_name .'</a>';

}
Run Code Online (Sandbox Code Playgroud)