• Resolved nicolasb827

    (@nicolasb827)


    Hello,
    I am using the REST API (through PHP package) to update/create new product.
    I defined in a filter function a new custom stock_status.
    But trying to update to this new status is not possible.

    In WC_Product::validate_props, the status is always (re)set:

                    if ( $stock_is_above_notification_threshold ) {
                            $new_stock_status = 'instock';
                    } elseif ( $backorders_are_allowed ) {
                            $new_stock_status = 'onbackorder';
                    } else {
                            $new_stock_status = 'outofstock';
                    }
    
                    $this->set_stock_status( $new_stock_status );

    So, how can I add my custom status ? Is there a safe way to do that without using a standalone plugin ?

    Thank you, Nicholas.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @nicolasb827

    I defined in a filter function a new custom stock_status.
    But trying to update to this new status is not possible.

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    If you’re not receiving input on this thread, I can recommend reaching out to one of the customization experts listed here: https://woocommerce.com/customizations/.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    This specific forum is more focused on the default WooCommerce core features.

    Lastly, for direct assistance with code customizations, I recommend consulting with the WooCommerce Customizations Partners. https://woocommerce.com/customizations/

    Thread Starter nicolasb827

    (@nicolasb827)

    Hello,
    sure, it is a complex topic 🙂

    IMHO, adding a filter hook to compute new_stock_status should be enough.
    It does not change logic in standard calls, and provides enough customisation.

    Any opinion is welcome 😉

    Nicholas.

    Hi @nicolasb827,

    Thanks for working with us on this. I did a bit of testing and the REST API did accept my custom order status. Here’s what I did.

    Added two custom order statuses using the code from this StackOverflow answer: https://stackoverflow.com/a/61798283
    Sent a PUT request to update an existing product:

    
    {
        "stock_status": "contact_us"
    }
    

    When I view the product, it’s showing the updated, custom status.

    Are you getting any error messages when you use the custom status with the REST API? If so, let us know what they are.

    Thanks!

    We haven’t heard back from you in a while, so I’m marking this thread closed for now – we’ll be here if and/or when you are ready to continue.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘[rest-api] setting product stock status to a custom status’ is closed to new replies.