• Resolved nordrium

    (@nordrium)


    Hello!
    I use your wonderful filter, but there is one problem.
    I am developing a theme for a website, for personal use, I wrote the code to determine what is displayed on the page, products or subcategories. Also, I use the condition of which template to display, depending on what is displayed on the page.
    And what’s the problem. After I select something in the filter and if I reload the page, an “Undefined variable $term” error appears
    Can you suggest how this can be fixed? I will provide code examples.

    Code to determine what is “on the screen” in functions.php

    function is_product_list_display_type( $term ) {
    	$taxonomy = 'product_cat';
    	if( ! term_exists( $term, $taxonomy ) )
    	return false;
    	if( ! is_numeric( $term ) )
    	$term = get_term_by( 'slug', sanitize_title( $term ), $taxonomy )->term_id;
    return get_term_meta( $term, 'display_type', true ) === 'products' ?  true : false;
    }

    Condition for choosing a template in taxonomy-produc-cat.php

    if(is_product_list_display_type( $term )){
    wc_get_template( 'archive-product-custom.php' ); 
    } elseif (is_subcategory_display_type( $term )) {
    	wc_get_template( 'archive-product-category.php' ); 
    } else {
    	wc_get_template( 'archive-product.php' );
    }

    Thanks you for help!

    • This topic was modified 3 years, 8 months ago by nordrium.
Viewing 1 replies (of 1 total)
  • Plugin Support mediawebster

    (@mediawebster)

    Hello

    It means you don’t have such a variable. Unfortunately I don’t know from where you take the $term.

    If it is an object of the current archive – try in Advanced->Options-https://c2n.me/4gRVvjf.png

Viewing 1 replies (of 1 total)

The topic ‘Reload page problem’ is closed to new replies.