Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

B2B Woocomerce

Options
  • 07-06-2017 3:37pm
    #1
    Registered Users Posts: 503 ✭✭✭


    I’m working on new woocommerce site which will be mainly used for B2C but got me thinking, it might be handy for our Wholesale customers if they could check up to date prices and maybe order online too.

    While there does appear to be a few wholesale plugins, they don’t appear to be geared towards B2B, as in, I don’t think I can set up Company A and allow user A & user B to order, see sales history etc from the same Company.

    I’ve seen some discussions on such a thing but haven't found anything suitable. Is there something like that, that I’ve missed?


Comments

  • Registered Users Posts: 6,499 ✭✭✭daymobrew


    I used the Dynamic Pricing plugin to allow a client accept wholesale orders on her website.

    http://www.damiencarbery.com/2017/03/use-dynamic-pricing-to-provide-wholesale-prices-in-woocommerce/

    It won't allow User A and User B see each other's orders though there should be a way to write code to allow that.


  • Registered Users Posts: 503 ✭✭✭Vex Willems


    daymobrew wrote: »
    I used the Dynamic Pricing plugin to allow a client accept wholesale orders on her website.

    http://www.damiencarbery.com/2017/03/use-dynamic-pricing-to-provide-wholesale-prices-in-woocommerce/

    It won't allow User A and User B see each other's orders though there should be a way to write code to allow that.

    Yeah I've seen that, and seems fine but without the feature I'd like.

    Whether it would be possible or not to code something, it would be beyond my skills to do so.


  • Registered Users Posts: 6,499 ✭✭✭daymobrew


    Whether it would be possible or not to code something, it would be beyond my skills to do so.
    I'll do a bit of an experiment early next week to see if I write a proof of concept. I would think of looking at something that works on the 'woocommerce_my_account_my_orders_query' filter to modify the 'customer' parameter.


  • Registered Users Posts: 6,499 ✭✭✭daymobrew


    Here is the start of some code that I have working. It gets the Billing Company of the current user and looks for other uses with the same billing company and displays their orders too.

    [PHP]add_filter( 'woocommerce_my_account_my_orders_query', 'cci_change_customer_id' );
    function cci_change_customer_id( $args ) {
    $current_user = wp_get_current_user();
    $current_user_billing_company = get_user_meta( $current_user->ID, 'billing_company', true );

    $user_query = new WP_User_Query( array( 'fields' => 'ID', 'meta_key' => 'billing_company', 'meta_value' => $current_user_billing_company ) );
    $same_company_users = $user_query->get_results();

    $args[ 'customer' ] = $same_company_users;
    return $args;
    }
    [/PHP]


  • Registered Users Posts: 503 ✭✭✭Vex Willems


    daymobrew wrote: »
    Here is the start of some code that I have working. It gets the Billing Company of the current user and looks for other uses with the same billing company and displays their orders too.

    Nice one!

    But could it be open to abuse? Could John from Company A find out what his competitor in Company B is ordering by changing the his company name from A to B?


  • Advertisement
  • Registered Users Posts: 6,499 ✭✭✭daymobrew


    But could it be open to abuse? Could John from Company A find out what his competitor in Company B is ordering by changing the his company name from A to B?
    Good point - in this code it would be open to such abuse.
    It might be fixed with the addition of another customer field, one that can only be seen by the shop manager or site admin.

    I'll continue with the path I am on as a proof of concept and I'll add a note of the potential for abuse.


  • Registered Users Posts: 503 ✭✭✭Vex Willems


    daymobrew wrote: »
    It might be fixed with the addition of another customer field, one that can only be seen by the shop manager or site admin.

    That would be an improvement alright, a shop code or password


  • Registered Users Posts: 6,499 ✭✭✭daymobrew


    Another small issue - the user does not have permissions to view another user's order. Thankfully I was able to copy and modify the WooCommerce that implements this restriction.

    The code below compares the billing company of the user and order. Obviously, for security, another bit of info should be compared.

    [PHP]add_filter( 'user_has_cap', 'cci_check_view_order_capability', 10, 3 );
    function cci_check_view_order_capability( $allcaps, $caps, $args ) {
    if ( isset( $caps[0] ) ) {
    switch ( $caps[0] ) {
    case 'view_order' :
    // Check that the current user billing_company and order billing company match.
    $current_user = wp_get_current_user();
    $current_user_billing_company = get_user_meta( $current_user->ID, 'billing_company', true );
    $order = wc_get_order( $args[2] );
    if ( $order && $current_user_billing_company == $order->get_billing_company() ) {
    $allcaps = true;
    }
    /*$user_id = $args[1];
    $order = wc_get_order( $args[2] );

    if ( $order && $user_id == $order->get_user_id() ) {
    $allcaps = true;
    }*/
    break;
    }
    }

    return $allcaps;
    }[/PHP]


  • Registered Users Posts: 6,499 ✭✭✭daymobrew


    I've written it up on my site.

    It would be good bit of work to expand because it would have to allow editing of the extra field in the order edit screen, user profile screen (but only by shop manager) and ensure that the data is padded to the order object (to store with the order). Some day...


Advertisement