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

7
我希望在用户收到“处理订单电子邮件”时添加产品链接,该电子邮件是在下单时发送的。当下单时发送订单电子邮件时,我希望在用户单击时获取产品链接,并在单击时重定向到详细产品页面。是否有任何方法可以获取产品链接或将产品标题转换为超链接。
谢谢。
4个回答

12

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

2
这个非常好用!非常感谢你抽出时间来帮忙并分享这个!! - jord8on

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

}

对于那些感兴趣的人,它应该放在functions.php文件中,而不是电子邮件模板中。我想让它可以在Facebook上分享。 - Jason

1
为了在订单邮件中将产品名称与其产品页面链接起来,请打开您的子主题的functions.php文件,并添加以下代码片段:

* Product Links in WooCommerce Order Emails
*/

    add_filter('woocommerce_order_item_name', 'woocommerce_order_item_link', 10, 3);

    function woocommerce_order_item_link( $item_name, $item, $bool ) {
        $url = get_permalink( $item['product_id'] ) ;
        return '<a href="'. $url .'">'.$item_name .'</a>'; 
    }


0

我一直在想这个是如何工作的。几乎没有什么详细的步骤说明信息可以获得。

我想到的最好的解决方案是编辑customer-processing-order.php文件。

我所做的就是用文本编辑器打开它,并添加了几行文本:

"您的订单已收到,正在处理中。以下是您的订单详细信息供您参考。请访问 "http://www.youlinkurl"。

最终用户不幸地需要复制并粘贴该链接,但至少它能够正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接