S
S
Smeecy Smeecy2021-07-01 10:37:14
WordPress
Smeecy Smeecy, 2021-07-01 10:37:14

How to apply a template to subcategories?

At the moment, the template only applies to the parent category, how can I apply it to all descendants of this category?

<?php 
    if ( ! defined( 'ABSPATH' ) ) {
        exit; // Exit if accessed directly
    }

    // Get current category slug
    global $wp_query;
    $cat_slug = $wp_query->query_vars['product_cat'];

    // Call template conditionally
    if($cat_slug == 'zakaznaya-produktsiya') {
        wc_get_template( 'archive-custom.php' );
    } else  {
        wc_get_template( 'archive-product.php' );   
    }
?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question