Home > Enterprise >  Custom Class wc_add_notice - Wordpress - Woocommerce
Custom Class wc_add_notice - Wordpress - Woocommerce

Time:08-25

Hello I have this code that creates a wordpress session message.

wc_add_notice(__('My mensaje!', 'mensajeper'), 'error');

This creates a message after reloading the page with the class

woocommerce-error

So far we are doing fine. How to add a custom class to this message for example

woocommerce-error-messageper

I am working with wordpress.

CodePudding user response:

WooCommerce doesn't offer a hook to change that. so you will need to overwrite the woocommerce template.

You need to copy the code from the error notice template here https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/templates/notices/error.php

and create the same file in ACTIVE-THEME-FOLDER/woocommerce/notices/error.php

with the class change.

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! $notices ) {
    return;
}

?>
<ul  role="alert">
    <?php foreach ( $notices as $notice ) : ?>
        <li<?php echo wc_get_notice_data_attr( $notice ); ?>>
            <?php echo wc_kses_notice( $notice['notice'] ); ?>
        </li>
    <?php endforeach; ?>
</ul>
  • Related