• Resolved ptienhung

    (@ptienhung)


    I use Dokan Multivendor, I want when a customer places an order, the system automatically sends the supplier’s bank account information to the customer’s email, and I use the following code.

    This code works fine with Woocomerce’s default email template, but it doesn’t work (doesn’t send the provider’s account information to the customer’s email) when I use YayMail – WooCommerce Email Customizer.

    Can you help me adjust the code so that it is compatible (works) with the “order processing” email template of YayMail – WooCommerce Email Customizer.

    Thank you very much!

    // *****Adding Vendor Bank Acc info on ordered item detail*****START
    remove_action( 'woocommerce_order_item_meta_start', 'dokan_attach_vendor_name', 10, 2 );
    
    // Add your supplier's account information before the "Order Details" section
    add_action('woocommerce_order_details_before_order_table', 'attach_vendor_info_before_order_table', 10, 1);
    
    // Add the supplier's account information to the email when the order is processed
    add_action('woocommerce_email_order_details', 'attach_vendor_info_to_email', 10, 4);
    
    function attach_vendor_info_before_order_table($order) {
        $vendor_info = get_vendor_bank_info_from_order($order);
    
        if (!empty($vendor_info)) {
            echo '<div class="vendor-bank-account">';
            echo '<h3>' . esc_html__('Vendor Bank Account Info', 'dokan-lite') . '</h3>';
            echo $vendor_info;
            echo '</div>';
        }
    }
    
    function attach_vendor_info_to_email($order, $sent_to_admin, $plain_text, $email) {
        // Only display the supplier's bank account information in the email sent when the order is processed
        if ($order->has_status('processing')) {
            $vendor_info = get_vendor_bank_info_from_order($order);
    
            if (!empty($vendor_info)) {
                echo '<div class="vendor-bank-account">';
                echo '<h3>' . esc_html__('Vendor Bank Account Info', 'dokan-lite') . '</h3>';
                echo $vendor_info;
                echo '</div>';
            }
        }
    }
    
    function get_vendor_bank_info_from_order($order) {
        $vendor_info = '';
    
        $items = $order->get_items();
        foreach ($items as $item_id => $item) {
            $product_id = $item->get_product_id();
            $vendor_id = get_post_field('post_author', $product_id);
            $store_info = dokan_get_store_info($vendor_id);
    
            if (isset($store_info['payment']['bank']['ac_name']) && isset($store_info['payment']['bank']['bank_name']) && isset($store_info['payment']['bank']['ac_number'])) {
                $ac_name = $store_info['payment']['bank']['ac_name'];
                $bank_name = $store_info['payment']['bank']['bank_name'];
                $ac_number = $store_info['payment']['bank']['ac_number'];
    
                $vendor_info .= '<p><span style="font-weight: bold">' . esc_html__('Vendor', 'dokan-lite') . ':</span> <a href="' . esc_url($store_info['store_url']) . '">' . esc_html($store_info['store_name']) . '</a></p>';
                $vendor_info .= '<p><span style="font-weight: bold">' . esc_html__('Account Name:', 'dokan-lite') . '</span> ' . esc_html($ac_name) . '</p>';
                $vendor_info .= '<p><span style="font-weight: bold">' . esc_html__('Bank Name:', 'dokan-lite') . '</span> ' . esc_html($bank_name) . '</p>';
                $vendor_info .= '<p><span style="font-weight: bold">' . esc_html__('Account Number:', 'dokan-lite') . '</span> ' . esc_html($ac_number) . '</p>';
    
                break;
            }
        }
    
        return $vendor_info;
    }
    // *****Adding Vendor Bank Acc info on ordered item detail*****END

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘I have a problem that needs to be processed via email: “Order Processing”’ is closed to new replies.