Need help solving problem with custom script
-
Hello, we used Yith Bundle plugin.
Also i managed to write a solution allowing Administrator user role can see outofstock products on backorder.
My solution working for simple, variables and other product types without yith-bundle.
My solution make yith bundle in backorder, even if bundle package products inside are outofstock or main bundle product is outofstock, but problem is i cannot add to cart this product.Code i writed:
// Custom conditional fuction to target specific user roles function is_allowed_user_role() { $targeted_roles = array('administrator', 'shop_manager'); // Here define your targeted user roles return (bool) array_intersect( wp_get_current_user()->roles, $targeted_roles ); } add_filter( 'woocommerce_product_get_stock_status', 'filter_product_stock_status' ); add_filter( 'woocommerce_product_variation_get_stock_status', 'filter_product_stock_status' ); function filter_product_stock_status( $stock_status ) { if ( is_allowed_user_role() && 'outofstock' === $stock_status ) { $stock_status = 'onbackorder'; } return $stock_status; } add_filter( 'woocommerce_product_get_backorders', 'filter_product_get_backorders' ); add_filter( 'woocommerce_product_variation_get_backorders', 'filter_product_get_backorders' ); function filter_product_get_backorders( $backorders ){ return is_allowed_user_role() ? $backorders : 'no'; } add_filter( 'woocommerce_product_backorders_allowed', 'filter_product_backorders_allowed', 10, 3 ); function filter_product_backorders_allowed( $allowed, $product_id, $product ){ return is_allowed_user_role() ? $allowed : false; }
Can you help me find a fix for this one?
Thanks!The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Need help solving problem with custom script’ is closed to new replies.