0

i have 2 categories that have book in adult, So i need when any user open this category to show him pop up message like :-

The content you are about to view are of a mature matter. Please be advised that the content may not be suitable for those under the age of 18

And when click yes,, we can show this category,But when select No ,, we need to return him to home page,

This two categories are for the WooCommerce plugin.

How can I do that?

1

1) Open your templates/content-product_cat.php file.


2) Locate the following piece of code:

<li <?php wc_product_cat_class(); ?>>
<?php do_action( 'woocommerce_before_subcategory', $category ); ?>

<a href="<?php echo get_term_link( $category->slug, 'product_cat' ); ?>">


3) Replace the line

<a href="<?php echo get_term_link( $category->slug, 'product_cat' ); ?>">

for the following piece of code:

<?php if ($category->name == "adults1" || $category->name == "adults2") { ?>

    <a onclick="return confirm('The content you are about to view are of a mature matter. Please be advised that the content may not be suitable for those under the age of 18')" href="<?php echo get_term_link( $category->slug, 'product_cat' ); ?>">

<?php } else { ?>

    <a href="<?php echo get_term_link( $category->slug, 'product_cat' ); ?>"> 

<?php } ?>


4) Replace "adults1" and "adults2" for the names of the two categories you want to control.

Hope it solves your issue.

0

Option 1) You'll need to use conditional tags to determine which category page is being shown. It's mentioned on the Woocommerce Docs.

  if ( is_product_category( array( 'abc', 'xyz' ) ) ) {
    //do this;
  } 

Option 2) And just in case, if you decide to render specific elements for those categories pages, you can do so by creating templates only for those categories at theme/woocommerce/templates & filenames would be taxonomy-product_cat-abc.php & taxonomy-product_cat-xyz.php

-1

You could simply add a Javascript Popup on them. In the page where your category name and links are generated add the code:

if ($term->name === 'adult1' || $term->name === 'adult2') {
  <a href="http://www.google.com/" onclick="window.alert('Google Link');">Google</a>
}
else {
<a href="http://www.google.com">Google</a>
}

The basic idea is to look if the category name is "adult1" or "adult2". If Yes then add a Javascript onclick(''); function to your link.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.