• Resolved tondegier

    (@tondegier)


    This cart stock reducer plugin works perfectly for simple products.
    But I only use varianble products and manage stock on variantion level.
    Then is plugin is not working and only reports that no stock is available.

    Is there a way to change the behaivior in such a way that variable products are supported.

    Kind regards,
    Ton de Gier

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author James Golovich

    (@jamesgol)

    You have to give more specific information about your setup. It does work with simple products and variants.

    Thread Starter tondegier

    (@tondegier)

    Hi James,

    You are right. It is working for variable products.
    Only not working for product weith setting “Allow backorders” .
    With this setting it should be possible to sell the product.
    But with this add-on this is not possible.

    Kind regards,
    Ton de Gier

    Plugin Author James Golovich

    (@jamesgol)

    Dealing with backordered products has been on the TODO list since I first developed the plugin. You are the first person I’ve heard from that has actually uses backorders.

    Thread Starter tondegier

    (@tondegier)

    Hi James,

    Yes, we use this for clothing products we don’t have on stock, but purchase this customer specific.
    So stock level is switched on and backorder order enabled.

    It would be a great plus if this is supported by your plugin.

    Kind regards,
    Ton de Gier

    Thread Starter tondegier

    (@tondegier)

    Hi James,

    Not very nice, but do not know how to make it proper.
    I added some extra line in the function to look for product backorder notification.
    If found then skip error message.
    Then backorder products are excluded from availablity check and stock reducer.

    Kind regards,
    Ton

    public function add_cart_validation( $valid, $product_id, $quantity, $variation_id = null, $variations = array() ) {

    $hostname = ” “;
    $username = ” “;
    $password = ” “;
    $database = ” “;

    // connection
    $conn = new mysqli($hostname, $username, $password, $database);

    if ( $this->item_managing_stock( $product_id, $variation_id ) ) {
    $available = $this->get_stock_available( $product_id, $variation_id );

    $results = “SELECT meta_value FROM wp_postmeta WHERE post_id = ‘$product_id’ and meta_key = ‘_backorders’ and meta_value = ‘notify'”;
    $backorder = $conn->query($results);

    if ( $q = $backorders->num_rows = 0 ) {
    if ( $available < $quantity ) {
    wc_add_notice( __( ‘Dit artikel en/of maat is niet meer beschikbaar’, ‘woocommerce-cart-stock-reducer’ ), ‘error’ );
    $valid = false;
    }
    }
    }
    return $valid;

    Plugin Author James Golovich

    (@jamesgol)

    I had some free time to look into this a bit more and it took some careful thought to figure out the best way to handle it. I’ve committed the change to the github repository, if you would like to test it out grab the latest version here https://github.com/jamesgol/woocommerce-cart-stock-reducer/archive/master.zip

    There are some possible situations that had to be handled. Your situation is an easier scenario, but if someone did have some items in stock and also wanted to have backordering enabled it gets more complicated.

    Plugin Author James Golovich

    (@jamesgol)

    I just released version 1.75 which addresses these issues. Please try it out!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Cart stock reducer for variant products’ is closed to new replies.