Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
568 B
4
Indexable
Never
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'custom_prevent_completed_order_email_for_b2b_users', 10, 2 );

function custom_prevent_completed_order_email_for_b2b_users( $recipient, $order ) {
    if ( ! is_a( $order, 'WC_Order' ) ) {
        return $recipient;
    }
    
    $user_id = $order->get_customer_id();
    
    if ( !$user_id ) {
        return $recipient;
    }

    $is_b2b_user = get_user_meta( $user_id, 'b2bking_b2buser', true );
    if ( $is_b2b_user === 'yes' ) {
        $recipient = '';
    }
    
    return $recipient;
}
Leave a Comment