• Resolved 1f2ns

    (@1f2ns)


    Community garden with rental beds (multisite).

    • only one per item
    • sold on a subscription basis
    • reorder synced to May 1, annually
    • name your own price, min $40.00/yr
    • 0.00 on signup

    If you sign up, the order is created as expected but stock is not reduced. Looking at the order comments I can see that there is a note added that reads: “stock levels reduced: 1 -> 1”

    My hunch was that this was related to one of the following:

    1. 0.00 item price
    2. subscription sync to a future date

    After troubleshooting I have been able to conclude the following:

    • 0.00 signup + subscription sync: order status is moved directly to complete, stock is not reduced (1 -> 1)
    • 1.00 signup + subscription sync: order status is moved to processing, stock is reduced (1 -> 0)

    Is this the expected functionality? Intuitively, I feel that stock should be reduced on the completion of an order even if the cost is 0.00 but I am unsure if this is a fringe case. Can any one confirm if this is as expected? And, if so, do you think it is a good idea to build out a MU plugin or snippet to alter this so stock is reduced on subscription when the initial order is 0.00?

    • This topic was modified 7 months, 1 week ago by 1f2ns.
    • This topic was modified 7 months, 1 week ago by 1f2ns.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @1f2ns,

    Which subscription plugin are you using? If you use the Woo Subscription plugin, this is the expected behavior, as it only reduces stock levels when payment is made. In this case, no payment is made for a $0.00 signup cost; hence, the stock is not reduced.

    do you think it is a good idea to build out a MU plugin or snippet to alter this so stock is reduced on subscription when the initial order is 0.00?

    If you want, you can use the woocommerce_order_status_completed hook to reduce the stock when an order is completed, regardless of the initial cost.

    Furthermore, if you use the Woo Subscription plugin and have a valid license with us, please open a support request so we can investigate your issue further.

    I hope this provides some clarity. Please let us know if you have any other questions!

    Thread Starter 1f2ns

    (@1f2ns)

    Thank you Shameem ??
    Yes, I am using the WooCommerce Subscriptions Plugin.

    For anyone else running into this, here is the snippet I wrote to address stock reduction for $0.00 items on an order. Good luck everyone.

    add_action( 'woocommerce_order_status_completed', 'reduce_stock_for_free_items' );
    
    function reduce_stock_for_free_items( $order_id ) {
        // Get the order object
        $order = wc_get_order( $order_id );
        
        // Loop through each order item
        foreach ( $order->get_items() as $item_id => $item ) {
            // Get the product
            $product = $item->get_product();
            
            // Check if the product exists and its price is $0.00
            if ( is_a( $product, 'WC_Product' ) && floatval( $product->get_price() ) == 0.00 ) {
                // Get current stock quantity
                $current_stock = $product->get_stock_quantity();
    
                // Only reduce stock if current stock is not null
                if ( !is_null( $current_stock ) ) {
                    // Calculate old stock for accurate logging before the reduction
                    $old_stock = $current_stock;
                    
                    // Reduce stock by the quantity ordered
                    $new_stock = wc_update_product_stock( $product, $item->get_quantity(), 'decrease' );
    
                    // Add a note to the order about the stock reduction
                    $order->add_order_note( sprintf( '0.00 Order - Stock levels reduced: %s (%s) %d→%d',
                        $product->get_name(), $product->get_sku(), $old_stock, $new_stock ) );
                }
            }
        }
    }

    Also, here is a snippet for stopping stock reduction on reorders on WooCommerce subscription reorders. Perfect solution for rental subscriptions (like raised garden beds.)

    https://github.com/woocommerce/woocommerce-subscriptions-do-not-reduce-stock-on-renewal

    • This reply was modified 7 months, 1 week ago by 1f2ns.
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @1f2ns,

    I’m glad you were able to find a solution to your inquiry here and thanks for sharing it with the community too! ??

    Should you have further inquiries, kindly create a new topic here.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WooCommerce 0.00 subscription not reducing stock’ is closed to new replies.