Чтобы отобразить свое пользовательское сообщение на странице оформления заказа перед сообщением о входе в Woocommerce и перед добавлением купонного сообщения, вместо этого вы будете использовать следующий код:
add_action('template_redirect', 'my_custom_message');
function my_custom_message() {
if ( ! is_user_logged_in() && is_checkout() && ! is_wc_endpoint_url() ) {
wc_add_notice( sprintf( __('This is my <strong>"custom message"</strong> and I can even add a button to the right… <a href="%s" class="button alt">My account</a>'), get_permalink( get_option('woocommerce_myaccount_page_id') ) ), 'notice' );
}
}
Код помещается в файл function.php вашей активной дочерней темы (или активной темы). Проверено и работает.
![enter image description here](https://i.stack.imgur.com/qAnKB.png)
Более простая версия для всех пользователей только на странице оформления заказа:
add_action('template_redirect', 'my_custom_message');
function my_custom_message() {
if ( is_checkout() && ! is_wc_endpoint_url() ) {
wc_add_notice( __('This is my custom message'), 'notice' );
}
}
Код помещается в файл function.php вашей активной дочерней темы (или активной темы). Проверено и работает.
![enter image description here](https://i.stack.imgur.com/JH4vn.png)