skip to Main Content

I have tried these but they ain’t working on WooCommerce shop pages:

add_action( 'the_content', 'age_verification_disclaimer', 10 );
add_filter( 'the_content', 'age_verification_disclaimer', 10 );

function age_verification_disclaimer( $content ) {

    $custom_content = '
    <div class="disclaimer-wrapper">
        <div class="disclaimer-container">
            Are you over 18 years old?<br />
            <br />
            <br />
            <a href="" class="button disclaimer-answer" data-answer="yes">'.__('Yes').'</a>
            <a href="" class="button disclaimer-answer" data-answer="no">'.__('No').'</a>
        </div>
    </div>
    ';
    
  $content .= $custom_content;
  return $content;
}

Tried to hook it on init, wp_head and wp_footer too…

What I’m trying to do is to show a layer on top of the site, to verify the users age.

2

Answers


  1. Chosen as BEST ANSWER

    After sleeping on it, I figured out that the WooCommerce pages ain't got the_content hook when they are selected as shop page. And after changing the function to echo the content and ditching returning $content it worked.


  2. You need to load this code in footer and with javascript check the right answer.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search