Okay
  Public Ticket #2812830
Sub User Email
Closed

Comments

  •  2
    Dan started the conversation

    My client would like to know:


    1. Once a sub account places an order, can it send the master account an email saying they need to approve an order.
  •  2,217
    WebWizards replied

    Hi Dan,

    Thank you for purchasing the plugin,


    This is not possible with B2BKing. The plugin does not have an order approval functionality between subaccounts - master accounts. The closest feature is that subaccounts can create purchase lists based on their needs, and then the master account can purchase these lists. The master account can also disable the permission to checkout for subaccounts, so that subaccounts would not be able to directly place orders and would have to work via lists.


    It's not exactly what you requested, but if you wanted to forward something like the "New Order / Order Received" email to the master account when a subaccount places an order, I can send you a code snippet that would do that, if it's helpful.


    Kind regards,

    Stefan

  •  2
    Dan replied

    Thanks for the information.  The code snippet would be very much appreciated.

  •  2,217
    WebWizards replied

    Hi Dan,

    The following PHP snippet will also send the "Order Received" email to the main/master account:

    add_filter( 'woocommerce_email_recipient_customer_processing_order', 'send_email_master_account', 10, 2 );
    function send_email_master_account( $recipient, $order ) {
        // Bail on WC settings pages since the order object isn't yet set yet
        $page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
        if ( 'wc-settings' === $page ) {
            return $recipient; 
        }
        
        // just in case
        if ( ! $order instanceof WC_Order ) {
            return $recipient; 
        }
        $customer_id = $order->get_customer_id();
        $account_type = get_user_meta($customer_id,'b2bking_account_type', true);
        $parent_email = 0;
        if ($account_type === 'subaccount'){
            $parent_user_id = get_user_meta($customer_id, 'b2bking_account_parent', true);
            // get parent email
            $parent_data = get_userdata($parent_user_id);
            $parent_email = $parent_data->user_email;
        }
        if ($parent_email !== 0){
            $recipient .= ', '.$parent_email;
        }
        return $recipient;
    }
    

    To add the snippet, you can use the following guide: https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/


    Kind regards,

    Stefan