2017-10-11 74 views
0

我已經制作了一個過濾器來更新woocommerce上的訂單顯示方式。 基本上我需要店主能夠點擊每個產品的名稱(現在鏈接到特色圖片),他也能夠看到URL(因爲圖片文件名對他們來說是有用的,以便跟蹤產品)在WooCommerce「New Order」產品標題中添加精選圖片網址

我需要這個隻影響發送給店主的NEW ORDER電子郵件。

我放在functions.php中的代碼確實更新了所有電子郵件中的BUT,並在網站上訂購了確認表。

有問題?我怎樣才能影響新的訂單電子郵件?我想我在這裏錯過了一些東西。

// item name link to product 

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

    $image = wp_get_attachment_image_src(get_post_thumbnail_id($_product->post->ID), 'full'); 

    return '<a href="'. $image[0] .'" rel="nofollow">'. $item_name .'</a> 
    <div style="color:blue;display:inline-block;clear:both;">'.$image[0].'</div>'; 

} 

回答

0

首先出現的是在你的代碼像一些錯誤:

  • 功能get_product()顯然是不合時宜的,並已取代wc_get_product()
  • 由於Woocommerce 3+ WC_Product屬性會直接訪問,而是使用可用的方法。

這裏是讓你期待(在「新秩序」管理員只通知)什麼是正確的方法:

// Your custom function revisited 
function display_product_title_as_link($item_name, $item) { 
    $product = wc_get_product($item['variation_id'] ? $item['variation_id'] : $item['product_id']); 
    $image = wp_get_attachment_image_src($product->get_image_id(), 'full'); 
    $product_name = $product->get_name(); 
    return '<a href="'. $image[0] .'" rel="nofollow">'. $product_name .'</a> 
    <div style="color:blue;display:inline-block;clear:both;">'.$image[0].'</div>'; 
} 

// The hooked function that will enable your custom product title links for "New Order" notification only 
add_action('woocommerce_email_order_details', 'custom_email_order_details', 1, 4); 
function custom_email_order_details($order, $sent_to_admin, $plain_text, $email){ 
    // Only for "New Order" and admin email notification 
    if ('new_order' != $email->id && ! $sent_to_admin) return; 
    // Here we enable the hooked function 
    add_filter('woocommerce_order_item_name', 'display_product_title_as_link', 10, 3); 
} 

代碼放在您的活動子主題的function.php文件(活動主題或任何插件文件)。

測試和WooCommerce工程3+

+0

感謝您的及時答覆並予補正的,我真的很感激。我已經測試過並能夠正常工作,但仍顯示客戶端收到的電子郵件中的更改。這兩個新的訂單通知管理員和客戶電子郵件有修改後的標題鏈接到圖像。我只需要在發送給店主的電子郵件中提供此信息。 – GauchoCode

+0

@GauchoCode ...對我來說,在我的測試服務器上它完美的工作(在WooCommerce版本3.1.2下)。我在測試之前從未發佈過答案......重要提示:在添加此代碼之前,您是否刪除了舊代碼? – LoicTheAztec

+0

我已經仔細檢查過,沒有我舊代碼的痕跡。就像你製作的一樣,這兩個電子郵件(客戶端和管理員)看起來都一樣,都有修改過的標題並顯示圖片網址。用Woo最新版本進行測試。我已經做了幾個測試,並在兩封電子郵件中都顯示相同... http://i63.tinypic.com/6hoo4l.png – GauchoCode

相關問題