我需要將產品鏈接放入發送給管理員的缺貨電子郵件中。
即使據我所知,我使用正確的過濾器鉤子,此代碼也沒有預期的結果?有什么建議嗎?
add_filter('woocommerce_email_content_no_stock', 'add_product_url_to_out_of_stock_email', 10, 2);
function add_product_url_to_out_of_stock_email( $message, $product ) {
global $product; // with or without this is the same result
return $message ."<br>\n". get_edit_post_link( $product->get_id() );
}
uj5u.com熱心網友回復:
您可以添加/使用WC_Product::get_permalink() – 產品永久鏈接來定制$message以滿足您的需求。
所以你得到:
function filter_woocommerce_email_content_no_stock ( $message, $product ) {
// Edit message
$message = sprintf( __( '%s is out of stock.', 'woocommerce' ), '<a href="' . $product->get_permalink() . '">' . html_entity_decode( wp_strip_all_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) . '</a>' );
return $message;
}
add_filter( 'woocommerce_email_content_no_stock', 'filter_woocommerce_email_content_no_stock', 10, 2 );
重要提示:默認情況下,此答案不起作用,因為wp_mail()用作郵件功能,其中內容型別text/plain不允許使用HTML
因此,要HTML使用 WordPress wp_mail()發送格式化的電子郵件,請添加這段額外的代碼
function filter_wp_mail_content_type() {
return "text/html";
}
add_filter( 'wp_mail_content_type', 'filter_wp_mail_content_type', 10, 0 );
相關:在 WooCommerce 中將產品超鏈接添加到低庫存通知電子郵件
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/406556.html
標籤:
