Hide Uncategorized category from WooCommerce pages

Couldn’t find any working snippet in Google, so I decided to write it myself. This snippet will hide the Uncategorized category from front-end.

Allow backorders for certain products in WooCommerce

Using this code snippet you can allow backorders for certain products.

Nginx and WordPress SEO by Yoast robots.txt 404 error message

I recently had an issue with robots.txt file and Google Search Console. It was showing a 404 error message. The problem was related to Nginx and Yoast SEO plugin. In my case, robots.txt is virtual and generated by Yoast SEO plugin. Nginx throws a 404 error because it can’t find the physical file, but then a request for robots.txt is detected by Yoast SEO plugin and the content is generated. However, Google bot stops at 404 error.

Basically, what you need to do is to add these lines to Nginx server blocks:

This means, Nginx will look for robots.txt through PHP and will not try to find a physical file.

How to add a custom field to WooCommerce checkout page

How to modify the WooCommerce API orders response?

How to modify the WordPress REST API posts response

The WordPress REST API is a great thing, but in most cases you need to extend it. For example, if you use Advanced Custom Fields and you need to get them via the API, then you need to modify the response. Here’s a quick example:

How to create a callback URL in WooCommerce

I was working on a payment gateway for WooCommerce and had to create a special URL that will then load the specified class method. Sometimes the information does not reach all parties e.g. if you close the browser and the status of the payment between the payment’s and merchant’s server remains unclear. The WooCommerce API allows you to create a callback URL.

Creating a callback URL

Calling a callback URL

Before WooCommerce 2.0, you could use:
http://yoursite.com/?wc-api=wc_gateway_my_gateway

In WoCommerce 2.0+:
http://yoursite.com/wc-api/wc_gateway_my_gateway/

DevSlider – A simple responsive slider built for Developers

There were many times when client asked me to customize the current slider template and add new settings to the slider. There are many great sliders in WordPress plugins repository, but they are not extendable – you can’t add new settings to the slider and change the template or it’s very hard. This time I decided to spend a bit more time and create my own slider which you can extend easily.

It uses bxSlider jQuery library and a Custom Post Type for slides. bxSlider has many options and examples. You can filter out bxSlider options by using devslider_slider_js filter and change them.

How to add slider to your page?

Use [DevSlider] shortocde. Available options are: slidewidth (default: 0), minslides (default: 1), maxslides (default: 1), category (default: all or category slug).

How to change the slider template?

The template file of DevSlider contains the markup and template structure for the front-end. This template file can be found within the /devslider/inc/ directory.

You can edit this template in an upgrade safe way through overrides. Simply copy devslider-template.php to your theme folder.

How to add new settings?

There are two ways. You can use Advanced Custom Fields plugin or WordPress meta boxes.

If you are going to use ACF, then you need to tell that to DevSlider by using devslider_use_wp_meta_boxes filter.

If you are going to use WordPress metaboxes, then you need to add a new meta box by using devslider_slider_settings_metabox action hook. For example, I’ll add a new input field for slide text.

We also need to hook into devslider_save_slide action hook to save it.

Now in wp-content/themes/yourtheme/devslider-template.php you can use slide text. (If you don’t see this file in your theme, then you can .copy it from the plugin inc folder).

You are welcome to contribute to this slider on GitHub.

Available action hooks

  • devslider_loaded
  • before_devslider_init
  • after_devslider_init
  • devslider_enqueue_scripts
  • devslider_add_meta_boxes
  • devslider_slider_settings_metabox – available argument $post
  • devslider_save_slide – available argument $post_id

Available filters

  • devslider_slider_js – bxSlider JavaScript code
  • devslider_use_wp_meta_boxes – available argument bool – true or false

WooCommerce REST API – Import products from JSON

I had a task to create a PHP script to import simple and variable products from JSON file using the WooCommerce REST API. Thought it might be worth sharing with others because I couldn’t find much information about products import from JSON using the API.

To make it easier to understand, I created a simple JSON file with one simple product and one variable product that have two product variations. You can get all files from Github repository.

products.json

Getting started

What you need to do is download a PHP wrapper for the WooCommerce REST API. You can download it using composer from https://packagist.org/packages/automattic/woocommerce If you don’t have composer yet, then you can download it from https://getcomposer.org

Setup

Setup for the new WP REST API integration (WooCommerce 2.6 or later):

1. Parse JSON

Convert JSON string to PHP array.

2. Get all product attributes from JSON

We need to get all product attributes names and values from JSON file.

3. Get products and variations from JSON for importing

4. Merge products and product variations

Used to loop through products, then loop through product variations.

5. A simple function to print status message

Import products to WooCommerce using the API

You can find the script on Github repository

My first package for Laravel – Google Safe Browsing Lookup (v4)

I’ve been working on an exciting project, and one of the first task was to integrate Google Safe Browsing into the project. The Safe Browsing APIs (v4) let you check URLs against Google’s constantly updated lists of unsafe web resources. However, I couldn’t find a working package for Laravel 5.4 so I decided to create my own and share it on github and packagist.

Installation

Run the following from the Terminal:

Next, add your new provider to the providers array of config/app.php:

Finally, add aliases to the aliases array of config/app.php:

Preparation

You need to get your API key from Google Safe Browsing API.

Publish the config file.

Set your API key in YOUR-APP/config/google_safe_browsing.php

Usage

More examples

License

The package is licensed under the GPL v3 License.