Blog

Hiding Cash on Delivery by Cart Total in WooCommerce

In the WooCommerce e-commerce system, you can define a certain limit to hide the cash on delivery. For example; If the total cart is less than $50, you can hide the cash on delivery option. Or, on the contrary, if the total cart is greater than $50, you can hide the cash on delivery option. […]

Hiding Cash on Delivery by Cart Total in WooCommerce

In the WooCommerce e-commerce system, you can define a certain limit to hide the cash on delivery. For example; If the total cart is less than $50, you can hide the cash on delivery option. Or, on the contrary, if the total cart is greater than $50, you can hide the cash on delivery option.

Today I will try to tell you how to hide the cash on delivery if the total cart is below a certain limit on your WooCommerce site. Before starting the process, do not forget to activate the Cash on Delivery field from WooCommerce> Settings> Payment area.

The products you sell on your e-commerce site may have a low price. You can use this feature if the option of cash on delivery creates a costly way for you while selling products for $5-10. In the scenario I prepared, if the total cart is less than $150, the cash on delivery option in the payment methods is hidden. By changing the value of < 150 in the codes to > 150, you can also hide the cash on delivery for orders with a cart total of $150 or more.

Add the code below to the functions.php file in your theme. If you do not know where the functions file in your theme is, use the Snippets plugin.

add_filter( 'woocommerce_available_payment_gateways' , 'change_payment_gateway', 20, 1);

/**
 * Hiding Cash on Delivery by Cart Total in WooCommerce
 * @param $gateways
 * @return mixed
 */
function change_payment_gateway( $gateways ){
    // Compare cart subtotal (without shipment fees)
    if( WC()->cart->subtotal < 150 ){
         unset( $gateways['cod'] );
    }
    return $gateways;
}

If you want to add code with the Snippets plugin, the example usage will be as follows. You can arrange the 150 fields in the code according to you.

Thanks for stop on WPServis! Hiding Cash on Delivery by Cart Total in WooCommerce is a basic WooCommerce tutorial. Please don’t forget to share this article on your social media profiles.

Leave a Reply

Your email address will not be published. Required fields are marked *