![](/img/trans.png)
[英]Woocommerce - wc_add_notice() not adding to session when nothing in the cart
[英]Custom Class wc_add_notice - Wordpress - Woocommerce
您好,我有這段代碼可以創建 wordpress session 消息。
wc_add_notice(__('My mensaje!', 'mensajeper'), 'error');
這會在使用 class 重新加載頁面后創建一條消息
woocommerce-error
到目前為止,我們做得很好。 例如,如何將自定義 class 添加到此消息
woocommerce-error-messageper
我正在使用 wordpress。
WooCommerce 沒有提供改變這一點的鈎子。 所以你需要覆蓋 woocommerce 模板。
您需要從此處的錯誤通知模板中復制代碼https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/templates/notices/error.php
並在 ACTIVE-THEME-FOLDER/woocommerce/notices/error.php 中創建相同的文件
隨着 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.