• Hi,

    Is it possible to age restrict certain WooCommerce categories with the plugin?

    This plugin is exactly what I need except not being able to age restrict categories as far as I can see.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @jorizz,

    This isn’t possible at the moment – I’ll look into it though. I think it’ll come down to restricting any taxonomy archive (or bypassing them).

    Thanks,
    Phil

    Thread Starter jorizz

    (@jorizz)

    Hi @philsbury,

    Thanks for looking into it I’m very interested.

    If there is any way I can achieve it right now with your plugin even if that means customizing a bit of code I’d be happy to try that.

    Thanks for your work,
    Joris

    Plugin Author Phil

    (@philsbury)

    It’s possible, easiest in the standard version;

    So, in age-gate/public/class-age-gate-public.php there’s a method called _ageRestricted around line 404.

    If you add something like this to the top of it before any of the other tests then it’ll work:

    
    if(is_archive()){
      $cat = get_queried_object();
      if(isset($cat->term_id) && $cat->term_id === 16){ // where 16 is the category ID
        return true;
      }
    }

    The queried object gives something like the following so if you don’t want to use an id there are other options:

    WP_Term Object
    (
      [term_id] => 16
      [name] => Category to be restricted
      [slug] => category-to-be-restricted
      [term_group] => 0
      [term_taxonomy_id] => 16
      [taxonomy] => product_cat
      [description] => 
      [parent] => 0
      [count] => 1
      [filter] => raw
    )

    Of course if you want to do multiple, you could do an in_array or something for the test.

    If you’re using the JS version, it might be a little more tricky, but probably workable.

    Cheers
    Phil

    Thread Starter jorizz

    (@jorizz)

    Thank you very much @philsbury.

    This helps me out greatly!

    Cheers and thanks,
    Joris

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Age restrict WooCommerce Categories’ is closed to new replies.