Public Ticket #2518587

allowing customers to place orders on out of stock items

Closed
Comments
2,762
KingsPlugins replied 6 years ago on August 26, 2020 at 2:50pm

Hi Tim and thank you for purchasing our plugin,

I think what you're looking for is a way to enable backorders, but only for B2B users. B2BKing doesn't have this function by default.


I looked around a little. 

Can you try and see if this code, added to functions.php, does what you need?

$user_is_b2b = get_user_meta(get_current_user_id(),'b2bking_b2buser',true);
if ($user_is_b2b === 'yes'){
    // Enable backorders on all products
    add_filter( 'woocommerce_product_get_backorders', 'filter_get_backorders_callback', 10, 2 );
    add_filter( 'woocommerce_product_variation_get_backorders', 'filter_get_backorders_callback', 10, 2 );
    function filter_get_backorders_callback( $backorders_status, $product ){    return 'yes'; // Enable without notifications
    }
    
    // the next 2 functions are possibly not necessary
    
    // Change all products stock statuses to 'instock'
    add_filter( 'woocommerce_product_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
    add_filter( 'woocommerce_product_variation_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
    function filter_get_stock_status_callback( $stock_status, $product ){    return is_admin() ? $stock_status : 'instock';
    }
    // Remove the stock quantity from displayed stock status
    add_filter( 'woocommerce_get_availability_text', 'filter_get_availability_text_callback', 10, 2 );
    function filter_get_availability_text_callback( $availability_text, $product ){    return __( 'In stock', 'woocommerce');
    }
}



2,762
KingsPlugins replied 6 years ago on August 26, 2020 at 4:52pm

glad to hear it works now! The price field is a custom field, so there's no way for another plugin to "understand" what that field contains, so I figured it must just be getting the price as it appears for your user. My guess is you shouldn't have any other issue if your user is set as B2C. If you have any other issue with this it's probably a cache that needs to be cleared.


Let me know if that backorder code works.

I need to sign off now but I'll get back to you as soon as I can.


Sign In