Ask Your Question
3

What is the way to modify the notification text when clicking on the add to cart button before selecting a variation in Woocommerce?

asked 2023-01-21 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-05-25 17:00:00 +0000

huitzilopochtli gravatar image

To modify the notification text when clicking on the add to cart button before selecting a variation in Woocommerce, you can use the following code snippet in your functions.php file:

add_filter( 'woocommerce_variation_is_active', 'custom_variation_is_active', 10, 2 );

function custom_variation_is_active( $active, $variation ) {
    if ( ! $variation->is_in_stock() ) {
        $active = false;
        wc_add_notice( __( 'Please select a different variation.' ), 'error' );
    }
    return $active;
}

This code will display the "Please select a different variation" message when the user clicks the add to cart button before selecting a variation. You can modify the message to suit your needs by changing the text inside the __('...') function.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-01-21 11:00:00 +0000

Seen: 1 times

Last updated: May 25 '22