2

can use hook (hack) in functions.php show custom message for guest users in woocommerce checkout page? Or from another way?

i need show message when active enabled registration on the checkout page. in woocommerce account settings. or enable guest checkout in checkout settings tab. because when deactivate this option, and guest option. one message show in checkout page (from woocommerce language file) esay change from edit language files.

I would show my custom message to visitors when options is active (enabled). In summary; my custom message show to unlogged users (visitors) and hide for logged visitors.

Any help is appreciated.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
ahmadwp
  • 228
  • 1
  • 4
  • 15

1 Answers1

4

To display a custom notice in checkout page for non logged users:

add_action('woocommerce_before_checkout_form', 'my_custom_message');
function my_custom_message() {
    if ( ! is_user_logged_in() ) {
        wc_print_notice( __('This is my custom message'), 'notice' );
    }
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • wow. the codes work correctly. you are the best. i have 2 question. 1. can change your simple text woocommerce message, mean 'This is my custom message' and replace with html and styled message. example create one or three line in wordpress visual editor in add post. and copy html code with some parts bold, linked, colors and etc and use this styled html code for woocommerce message in your functions code? my two question is can change message place? now message show in top checkout page, can change place and move message to bottom of checkout page? I'm sorry to bother you. thank you so much. – ahmadwp Jul 02 '18 at 06:48
  • 1
    You can replace `wc_print_notice();` by a custom html formatted message. To display the message in the bottom you will have to use `woocommerce_after_checkout_form` hook instead. – LoicTheAztec Jul 02 '18 at 07:26
  • thank you very much. woocommerce_after_checkout_form work correct. but when copy and paste ustom html formatted message replacec with wc_print_notice( __('This is my custom message'), 'notice' ); line, wordpress code editor not accept my custom code. Should I remove this whole this line? and replace with my custom message; or only remove This is my custom message and replace with? im test my way and work correct. Did I understand correctly? or must be paste my custom formatted code in html tag? mer30 – ahmadwp Jul 02 '18 at 07:50
  • Thank you so much for your kindness. ok works good. but not show in woocommerce pretty message box and display as clear and not in message box. but work correctly. – ahmadwp Jul 02 '18 at 08:09
  • can show messege higher than woocommerce_before_checkout_form ? mean; the first message in top checkout form. higher than login in notice and coupen code notice – ahmadwp Jul 02 '18 at 09:02
  • 2
    @ahmadsh I don't catch what you really want and it 's out the scope of your initial question. You should better ask a new question, trying to explain clearly what do you want, where do you want and how do you want it, adding in your new question the code that you are using, giving us all necessary details, screenshots and explanations. – LoicTheAztec Jul 02 '18 at 13:30
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/174172/discussion-between-ahmadsh-and-loictheaztec). – ahmadwp Jul 02 '18 at 13:32