Category: WooCommerce

  • WooCommerce emails add reply to header

    WooCommerce emails add reply to header

    A client was having issues with bounce back due to customers entering incorrect email addresses, so I updated the outbound email address used by WooCommerce to “[email protected]”, this meant any bounce backs would go to a null mailbox instead of to their mains “[email protected]” mailbox. However, this meant when customers hit reply, it would reply to the noreply@ mailbox. Using this code, I was able to set a Reply-To header, so customers could still reply to emails.

    Code

    Drop this into your functions.php file and edit as required.

    This code is provided as it and may require changes to work for your needs.

  • WooCommerce admin filter products by image

    A client recently asked me to add a filter to the WooCommerce admin products list so they can filter items based on if the item had an image or not. This allowed them to easily find products which had missing images so they could correct.

    Why not take a look how to filter by on sale items?

    Code

    This code is provided as it and may require changes to work for your needs.

  • WooCommerce delayed webhooks using actions scheduler

    Recently been contacted by a user who needed the ability to delay the WooCommerce webhooks by x time, this would allow other processes happening on the site to finish instead of firing the webhook straight away, for example waiting for the payment process to finalise. Delaying webhooks is not common practice, however some time special case arises!

    Take a look at actions scheduler if you wish to read more into the scheduler system used by WooCommerce.

    Code

    The following code allows you to delay several WooCommerces webhooks by a set duration (seconds) and also run in two modes.

    1. Single Webhook, creates 1 single webhook but delayed by x seconds.
    2. Multi Webhook, creates 2 webhooks, the normal webhook created by WooCommerce and a second repeat webhook which runs x seconds later.

    This code is provided as it and may require changes to work for your needs.

     

  • 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.

  • WooCommerce fix slow or delayed webhooks and achieve instant webhook firing

    I’ve recently been working on a project which synced data between WooCommerce and an internal warehouse system, I was utilising the WooCommerce webhooks to achieve near real time syncing between the two systems, without having the creating API scripts to poll for data on a regular basis.

    The Problem?

    There was a delay ranging from couple seconds to 1 minute, WooCommerce uses a system called actions scheduler, this is an improved wordpress cron, allowing background processing to occur within WordPress for single or recurring actions. This is great and what WooCommerce utilises for its web hook system, however it is backed by the word press cron and the next load of scheduled actions will run on the next cron run (every 1 minute).

    For this project, I needed the web hooks to fire as soon as the button was clicked, and a possible delay up to 1 minute was to long.

    Fix

    Disable async web hooks, web hooks will not fire as soon as they are created as part of the browser request.

    I would recommend you test your site after doing this change, for example order webhooks will fire when a customer creates a new order, which could lead to a slow user experience.

  • WooCommerce admin products filter by on sale

    WooCommerce admin products filter by on sale

    I needed the ability to filter the WooCommerce products list within admin by products which where on sale. This was to allow the client to easily find products they have put on offer within certain categories. The below code achieves this.

    It does need some work, as it currently ignores the on sale start and end dates, however you should be able to easily modify it for this purpose.

     

    This code is provided as it and may require changes to work for your needs.

  • WooCommerce products filter by tags within admin

    Need the ability to filter the WooCommerce products list within admin by tags? Snippet of code below is for you. This concept can be edited for other purposes.

    This can be easily changed to work in different scenarios.

    Found this snippet on the following website.

    https://businessbloomer.com/woocommerce-display-custom-filters-wp-dashboard-products/


  • WordPress remove Yoast SEO post filters

    Yoast SEO is a great SEO tool, I install it on most of the websites I build, but somes times I just dont need or want the filters it adds at the top of the admin posts pages. The most annoying one is when it adds it to products on a WooCommerce store.

    Below snippet will remove the Yoast SEO filters from admin.

    This could be upgraded for future use, for example only remove fields on WooCommerce product lists.

  • 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.