skip to Main Content

I want to add an extra class to my WooCommerce notice.

Here’s my current code for printing the notice:

wc_print_notice( 'My message', 'success' );

I saw in the WooCommerce Docs, that there is an option to add extra $data to the notice.

But something like this won’t work (it adds only data-class="extra" to it):

wc_print_notice( 'My message', 'success', array('class' => 'extra') );

Is there an option to do this or am I misunderstanding something?

2

Answers


  1. Chosen as BEST ANSWER

    I found an optional solution for my case. It would be possible to simply style the notice with the data attribute. Like this:

    .woocommerce-message[data-class="extra"] {
        background-color: red;
    }
    

  2. There’s no way to add extra class within the function, nor is there a filter to use.

    What you can do is overwrite the template, by copying to yourtheme/woocommerce/notices/notice.php (or success.php)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search