向woocommerce电子邮件中添加其他详细信息

问题描述 投票:0回答:1

我的Woocommerce网站是一个交易平台,我想在Woocommerce订单电子邮件中输出供应商商店徽标(WC Vendors插件)的图像。因此,当客户收到订单电子邮件时,他们可以在订单电子邮件中看到卖方商店的徽标。我尝试了下面的代码,但不确定为什么不输出图像。在数据库中,商店徽标位于_wcv_store_icon_id下。

add_action('woocommerce_email_after_order_table', '_wcv_store_icon_id', 10, 4);
function _wcv_store_icon_id( $order,  $sent_to_admin,  $plain_text,  $email ){
    foreach($order->get_items() as $item_values){
        // Get the product ID for simple products (not variable ones)
        $product_id = $item_values['product_id'];
        $vendor_shop    = urldecode( get_query_var( 'vendor_shop' ) );
        $vendor_id      = WCV_Vendors::get_vendor_id( $vendor_shop );
        $output = wp_get_attachment_image_src( get_user_meta( $vendor_id, '_wcv_store_icon_id', true ), 'full' );

    if ( is_array( $output ) ) {
        $img = $output[0];
    }
    return $img;
}
php wordpress woocommerce hook-woocommerce
1个回答
0
投票

您需要意识到一个订单中可以有多个供应商。因此,您将在电子邮件中添加每个供应商站点图标。话虽如此,以下将在订单表之后输出每个图标。

add_action('woocommerce_email_after_order_table', '_wcv_store_icon_id', 10, 4);
function _wcv_store_icon_id( $order,  $sent_to_admin,  $plain_text,  $email ){
        foreach( $order->get_items() as $item_values ){
            $product_id = ! empty( $order_item['variation_id'] ) ? $order_item['variation_id'] : $order_item['product_id'];
            $vendor_id  = WCV_Vendors::get_vendor_from_product( $product_id );
            $icon_src = wp_get_attachment_image_src( get_user_meta( $vendor_id, '_wcv_store_icon_id', true ), 'full' );
            $has_icon = is_array( $icon_src ); 

            if ( $has_icon ){ 
                return echo $icon_src[0]; 
            }
    }
© www.soinside.com 2019 - 2024. All rights reserved.