• Resolved audat

    (@audat)


    Hello!

    We use webhooks to sync order data. For variable products, the category is empty.
    “categories”: [],

    Any suggestions on what causes this? Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hey @audat,

    That’s interesting. I set up a quick test on my site to send data to webhook.site whenever an order is created. I’m not seeing a line for the category at all in the post that is sent. Here’s a screenshot of the order item data.

    data

    Which topic are you using with your webhook?

    Thanks!

    Thread Starter audat

    (@audat)

    Hello @3sonsdevelopment ,

    Thank you for testing and confirming. We use the woocommerce order updated webhook successfully to send order information to a CRM. That works for Simple Products, the category is passed by.

    Only the category for recently added variable products is empty.

    Line 62-66 from the json of an order updated webhook of a variable product:

      "categories": [],
      "tags": [],
      "images": [
        {
          "id": 30943,
    • This reply was modified 4 years, 10 months ago by audat.
    • This reply was modified 4 years, 10 months ago by audat.
    Thread Starter audat

    (@audat)

    Hello @3sonsdevelopment,

    We are using the webhooks product.updated and product.created.

    I can see that the categories are visible for the main product:
    “categories”: [
    {
    “id”: 114,

    But for the product variations, categories is empty:
    “categories”: [],
    “tags”: [],

    Do you know how we can fix this? Thanks!

    Hey @audat,

    Thanks for the extra details here. I suspect that’s because variations inherit the category of the parent. They not actually assigned to categories themselves.

    But the parent’s category isn’t stored for the variations in the database. I suspect that’s why the category is empty for these variations.

    You may be able to change this, but it will require some extra coding to do that. I’ll leave this open for a while to see if anyone chimes in with some help there.

    You could also ask in the WooCommerce community Slack and see if anyone there has an idea of how to approach this.

    https://woocommerce.com/community-slack/

    Take care

    Thread Starter audat

    (@audat)

    Hello @3sonsdevelopment, thank you for pointing that out! I’ll try the slack community.

    Have a nice day!

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, and there haven’t been any further replies, so I’m going to mark this as resolved – if you have any further questions, please start a new thread.

    Thread Starter audat

    (@audat)

    Hello Jesse, the problem is not resolved yet.

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @audat I double checked what happens when the product.updated webhook is sent for a variable product. There is a webhook sent for the product and each variation that has been updated. Due to the variation does not have a category applied in the database it is not included in the webhook delivery. The category is added to the parent product’s webhook body since it is a term for the post/product.

    In order to get the category from the parent product into the webhook body for the variation, custom code will need to be implemented. I’d suggest trying the woocommerce_rest_prepare_webhook_delivery filter, checking to see if it’s a variation, then getting the parent product’s categories and add them to the response if they are needed.

    Thread Starter audat

    (@audat)

    @jessepearson Thank you! Can you give me a hint on how to add the category to the response?

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @audat It’s not a simple 1-2 line snippet to be able to do that. You would need to get the parent_id, then query the terms, then add them to the response.

    This is where the categories data is grabbed during the product build for webhook delivery, which should be a good starting point:
    https://github.com/woocommerce/woocommerce/blob/4.3.0/packages/woocommerce-rest-api/src/Controllers/Version2/class-wc-rest-products-v2-controller.php#L663

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Variable Product: empty “categories” in Webhook’ is closed to new replies.