0
votes

My Woocommerce site is a marketplace platform and I want to output the image of vendor's store logo (WC Vendors plugin) in the Woocommerce order emails. So when a customer receives the order email they can see the vendor store's logo in the order email. I tried the code below but not sure why the image is not being outputted. In the database, the store logo is placed under _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;
}
1

1 Answers

0
votes

You need to realise that there can be multiple vendors in an order. So you would be adding every single vendors site icon to the email. That being said, the following will output every icon after the order table.

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]; 
            }
    }