Create a folder if it doesn’t already exist in PHP

You can check whether the folder is exits or not by using file_exists(). You can also create folder by using mkdir(). See below example code to create folder if it doesn’t already exits in PHP.

if (!file_exists('path/to/directory')) {
mkdir('path/to/directory', 0777, true);
}

Have any doubt, then comment here!

What is WordPress hooks? What are WordPress hooks?

WordPress Hooks are the functions that can be applied to an Action or a Filter in WordPress.
Two types of hooks exist in WordPress. That are

  1. Action
  2. Filter

Action hooks allow you to add additional code to the WordPress core or theme so that you can achieve some new functionality or customizations.
It can be handled by add_action() and do_action().

Filter hooks allow you to control how something happens or change something that’s already being output.
It can be handled by add_filter and apply_filter().

How to get using current WordPress version programmatically?

You can get the WordPress version using the following code:

$version=bloginfo('version');
echo $version;

Here $version displays the WordPress Version you use. You can get different information about the current site by passing parameters to bloginfo(). Some important parameter’s are listed below

  1. name
  2. description
  3. html_type
  4. url
  5. admin_email
  6. language
  7. stylesheet_directory
  8. template_directory

Have any doubt, then comment here!

Disable Payment Gateway for a Specific Country in WooCommerce

If you want to disable payment gateway for a specific country in WooCommerce then you have to decide the payment gateway and country code. Here I’m disabling the cod for India. You have to replace “cod” instead of your payment gateway. Have to replace “IN” instead of your decided country code. Place the following code in your functions.php file.

function disable_payment_gateway_for_a_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() == 'IN' ) 
{
unset( $available_gateways['cod'] );
} 
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'disable_payment_gateway_for_a_country' );

Have any doubt, then comment here!