【问题标题】:WooCommerce Add Product Link in Processing Order EmailWooCommerce 在处理订单电子邮件中添加产品链接
【发布时间】:2022-03-18 20:57:00
【问题描述】:

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

谢谢

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    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】:

    我目前正在使用此解决方案,我在另一页的 cmets 中找到了该解决方案。这不是我的代码。

    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 上共享。
    【解决方案3】:

    要将产品名称与其订单电子邮件中的产品页面链接,请打开子主题的functions.php文件并添加以下代码sn-p:

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

    【讨论】:

      【解决方案4】:

      我一直想知道这也是如何工作的。任何地方都几乎没有可用的信息 - 至少没有多少详细的分步说明。

      我想出的最佳解决方案是编辑 customer-processing-order.php。

      我所做的只是在文本编辑器中打开它并添加几行文本到:

      “您的订单已收到,正在处理中。您的订单详情如下所示,供您参考。请访问“http://www.youlinkurl”。

      不幸的是,最终用户将不得不复制并粘贴该链接,但至少它可以工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-23
        • 1970-01-01
        • 2020-12-15
        • 1970-01-01
        • 1970-01-01
        • 2021-07-14
        • 2013-01-06
        • 1970-01-01
        相关资源
        最近更新 更多