Support » Plugin: YITH WooCommerce Product Bundles » Need help solving problem with custom script

  • danna556

    (@danna556)


    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!

    • This topic was modified 3 months ago by danna556.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support Alessio Torrisi

    (@alessio91)

    Hi there,
    I added a new filter to let you add the product to the cart.
    Please click here to download a file and move it following path
    wp-content\plugins\yith-woocommerce-product-bundles\includes\class.yith-wcpb-frontend.php

    Then add following code in the file functions.php of your theme.
    add_filter( 'yith_wcpb_check_product_stock', '__return_false' );

    We’ll wait for your feedback.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.