Category: Programming & Development

  • Ubuntu EC2 configure Amazon Time Sync Service for Amazon AWS

    Having problems keeping your server time in sync? or a project requiring accurate timing? If your using a Amazon EC2 instance you can swap to using Chrony and Amazon Time Sync using the below commands.

    (more…)

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

  • Flexbox Interactive Cheatsheet

    Flexbox is a great new tool we can fit into the web development toolkit, with Bootstrap 4 and other frameworks moving across to flexbox, it is becoming more important to start learning it.

    Found this great cheat sheet which has interactive demos / explanations, there is plenty other resources out there, but I find this one easy to quickly get my bearings if the brain freezes!

    https://yoksel.github.io/flex-cheatsheet/

  • Cool CSS3 Animated Weather Icons using CSS3

    Cool CSS3 Animated Weather Icons using CSS3

    Lately I have been working on a full screen office dashboard project which is going to be shown on various 50″ screens throughout an office space, wanted to add some basic information such as weather! Came across this cool CSS3 written animated weather icons.

    Give it a look and thank you to the author

    https://codemyui.com/animated-weather-icons-in-css/

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

  • Using NANO with crontab for CentOS

    I dont like or know how to use VI correctly and by default CentOS likes to open everything in VI, I prefer nano and find when trying to edit the crontab CentOS always wants to use VI.

    Below command solves this issue and allows the use of nano for editing crontab. You will need to try either of the solutions below, I have found some servers both work, some only one or the other works.

  • Control windows docker with Windows 10 Ubuntu Linux subsystem

    Windows 10 Linux subsystems are a very powerful feature and expand the capabilities for Windows based developers greatly, without the need to use VMs or dual booting. One of these is controlling your windows based docker host via your Linux subsystem.

    Why?

    Linux command line is much more powerful that windows standard cmd line, you can combine a number of tools using piping to perform complex operations all via cli. Many of the tutorials, guides and normal operating commands used by docker and other tools are written using Linux based command line.

    1. Setup Linux Subsystem

    First you need to have your linux subsystem all setup and running. here is a guide I previous wrote to do just that.

    All commands below will be via your linux subsystem.

    Windows 10 Subsystem for Linux Ubuntu

    2. Updates and packages

    3. Add Docker’s official GPG key

    4. Add repository

    5. Install docker client

    6. Add docker host to bash profile

    This is so that you dont have to keep telling docker client how to access the docker service.

    7. Enable exposed daemon with docker

    We are almost done, now we just need to go back to our windows system and enabled exposed daemon via the docker settings.

    Right click the docker icon within your task area and choose settings.

    The general tab should have a “Expose daemon on tcp://localhost:2375 without TLS”, enable this option.

    You should now be able to control your Windows docker service via your Linux subsystem.

    Note

    There is a more secure way to establish a connect between your subsystem and docker client, have a look at the following guide.

    [Cross Post] WSL Interoperability with Docker