Category: PHP

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!

Remove related products from product page in WooCommerce

If you want to remove related products from product page in WooCommerce then place the following code in your functions.php file.

function wc_remove_related_products( $args ) {
	return array();
}
add_filter('woocommerce_related_products_args','wc_remove_related_products', 10); 

Have any doubt, then comment here!

How to get number of item in WooCommerce cart?

If you want to get number of items in a WooCommerce cart then you can place the following code in your file.

global $woocommerce;
$count=$woocommerce->cart->cart_contents_count;

Here $count having total number of items in your WooCommerce cart.
Have any doubt, then comment here!