[英]Custom Class wc_add_notice - Wordpress - Woocommerce
Hello I have this code that creates a wordpress session message.您好,我有这段代码可以创建 wordpress session 消息。
wc_add_notice(__('My mensaje!', 'mensajeper'), 'error');
This creates a message after reloading the page with the class这会在使用 class 重新加载页面后创建一条消息
woocommerce-error
So far we are doing fine.到目前为止,我们做得很好。 How to add a custom class to this message for example
例如,如何将自定义 class 添加到此消息
woocommerce-error-messageper
I am working with wordpress.我正在使用 wordpress。
WooCommerce doesn't offer a hook to change that. WooCommerce 没有提供改变这一点的钩子。 so you will need to overwrite the woocommerce template.
所以你需要覆盖 woocommerce 模板。
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您需要从此处的错误通知模板中复制代码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并在 ACTIVE-THEME-FOLDER/woocommerce/notices/error.php 中创建相同的文件
with the class change.随着 class 的变化。
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.