Tag: store

  • Fix WooCommerce webhook loop when using WooCommerce API

    Problem (Quick)

    Updating a product via the WooCommerce API would fire an update webhook, causing a loop of webhook and API activity which never ended.

    Problem

    Created a script which keeps stock levels synced between WooCommerce and a stock management system, WooCommerce WebHooks are used to set products stock levels in near real time. Using WooCommerce API new stock levels are pushed to WooCommerce, however with each API push this would trigger a product updated webhook, causing my script to reinforce the stock levels via API (causing an unlimited updating loop).

    Solution

    We can use  woocommerce_webhook_should_deliver  filter to control if a webhook should be delivered.

    The following example shows how I used the clients IP address (in this example my scripts server) to stop webhook delivery for any requests from that IP address, this allows my script to use the API and webhooks will never be delivered.

  • Fix for WooCommerce schema data missing brand and mpn

    Fix for WooCommerce schema data missing brand and mpn

    UPDATED 25/10/2021 to comply with latest google changes.

    Today I came across and issue where Google Search Console was complaning products “brand” and “mpn” where missing from the products schema / rich snippets data. You can checking using the rich snippet testing tool by Google found here.

    https://search.google.com/structured-data/testing-tool

    I fixed my issue by adding a WordPress filter using the “woocommerce_structured_data_product” filter option. This allows you to add new data to the already generated WooCommerce data.

    This is an example. You will need to change for your implementation.