PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 18, 2022

[FIXED] remove_action wc_empty_cart_message not working in WooCommerce

 January 18, 2022     hook-woocommerce, php, woocommerce, wordpress     No comments   

Issue

I would like to REMOVE completely the wc_empty_cart_message. My site has no cart. and when the item is removed from checkout the user is redirected to the home page. But then upon browsing to a shop page, the message "your cart is not available whilst your checkout is empty" appears and is completely unnecessary.

I have seen many of questions/answers about how to change the message to something else (I tried some of them which also did not seem to work).

I tried this which seems to be the right thing to do, but for some reason it does not make any visible change on my website.

remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );

Is there any way to check which hook is creating the message from the front-end? Or any way how I can see what is overruling this command from executing?


Solution

To remove the "Your cart is currently empty" message, use:

function action_woocommerce_cart_is_empty() {
    // Remove
    remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );  
}
add_action( 'woocommerce_cart_is_empty', 'action_woocommerce_cart_is_empty', 9, 0 );

Where the remove_action in an add_action with a lower priority number (9)


To remove the "Checkout is not available whilst your cart is empty" message, use:

function filter_woocommerce_add_notice ( $message ) {
    // Equal to (Must be exactly the same).
    // If the message is displayed in another language, adjust where necessary!
    if ( $message == 'Checkout is not available whilst your cart is empty.' ) {
        return false;
    }   
    
    return $message;
}
add_filter( 'woocommerce_add_notice', 'filter_woocommerce_add_notice', 10, 1 );


Answered By - 7uc1f3r
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing