简体   繁体   中英

Custom Class wc_add_notice - Wordpress - Woocommerce

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.

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 class="woocommerce-error woocommerce-error-messageper" 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM