How to Hide Payment Icons on the Cart Total for Free in WordPress

Home » Snippets » How to Hide Payment Icons on the Cart Total for Free in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you running an e-commerce store on WordPress and want to hide the payment icons on the cart total page for free products? By default, WooCommerce displays the payment icons even when the cart only contains free items, which can be confusing for customers. In this article, we’ll show you how to easily hide the payment icons on the cart total page for free products, providing a smoother and more seamless checkout experience for your customers.

					function wpturbo_hide_payment_icons() {
    if ( WC()->cart->subtotal == 0 ) {
        remove_action( 'woocommerce_review_order_before_payment', 'woocommerce_checkout_payment', 10 );
    }
}
add_action( 'wp', 'wpturbo_hide_payment_icons' );
				

To hide payment icons in the cart total when the subtotal is free, we can use the code snippet provided.

The code snippet starts by defining a new function called wpturbo_hide_payment_icons(). This function will be responsible for checking the subtotal of the WooCommerce cart and hiding the payment icons if the subtotal is zero.

Inside the function, we use an if statement to check if the cart subtotal is equal to zero. The condition is checked using the WC()->cart->subtotal property, which represents the current subtotal of the cart.

If the condition is true, we use the remove_action() function to remove the action woocommerce_checkout_payment from the hook woocommerce_review_order_before_payment. This action is responsible for displaying the payment icons in the cart total section.

By removing the action, we prevent the payment icons from being rendered on the cart page when the subtotal is zero.

To trigger the wpturbo_hide_payment_icons() function, we use the wp hook. This ensures that the function is executed on the WordPress front-end after all the necessary classes and functions are loaded.

Once the code snippet is added to your WordPress theme or plugin, the payment icons in the cart total section will be hidden when the subtotal is zero. This can be helpful if you want to provide a free product or service without displaying any payment options to the user.

Register an account to save your snippets or go Pro to get more features.