【发布时间】:2019-08-02 17:18:19
【问题描述】:
我正在尝试在订单电子邮件标题中输出产品的自定义字段。这个钩子是woocommerce_email_header ($email_heading, $email)。我尝试了下面的代码,但它不适用于woocommerce_email_header,我在结帐时遇到内部服务器错误。
add_action('woocommerce_email_header', 'wcv_ingredients_email_logo', 10, 4);
function wcv_ingredients_email_logo( $order, $sent_to_admin, $plain_text, $email_heading, $email ){
foreach($order->get_items() as $item_values){
// Get the product ID for simple products (not variable ones)
$product_id = $item_values['product_id']; //get the product ID
$image_id = get_post_meta( $product_id, 'store_email_logo', true ); //get the image ID associated to the product
$image_src = wp_get_attachment_image_src( $image_id, 'full' )[0]; //get the src of the image - you can use 'full', 'large', 'medium', or 'thumbnail' here,
$image = '<img src="'.$image_src.'">'; //create the img element
echo $image . '<br>'; //echo the image
}
}
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce