Okay
  Public Ticket #3209823
Sending a notification to an additional email address about a new order/sale of a b2b client
Closed

Comments

  • Evgeny started the conversation

    Good afternoon!

    Can I somehow send new b2b orders to additional email addresses? And how can I use php to show the required content only to b2b users. The site works in hybrid mode.

    Thank you


  •  1,904
    WebWizards replied

    Hi Evgeny,

    Thanks for getting in touch,


    To show specific content only to B2B users, you can use our plugin's content restriction shortcode: https://woocommerce-b2b-plugin.com/docs/shortcode-to-restrict-content-to-b2b-b2c-user-groups-specific-users/

    If you need this while writing PHP code, you could use use code such as: 

    echo do_shortcode('[b2bking_content show_to=b2b]Your content here...[/b2bking_content]'); 

    The following snippet should also send any order emails for B2B users to [email protected]

    add_filter( 'woocommerce_email_recipient_new_order', 'send_email_to_agent_function', 10, 2 );
    function send_email_to_agent_function( $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();
        $customer_is_b2b = get_user_meta($customer_id,'b2bking_b2buser', true);
        if ($customer_is_b2b === 'yes'){
            // send email to agent as well
            $agent_email = '[email protected]';
            $recipient .= ', '.$agent_email;
        }
        return $recipient;
    }
    

    You can also change '[email protected]' to something like '[email protected][email protected][email protected]' etc, in order to send it to multiple addresses.


    I understand that you have already purchased the B2BKing plugin?

    In that case, please send us your purchase code / license key for the plugin so we can add it to our database, thank you.


    Kind regards,

    Stefan