• Resolved coinlegend

    (@coinlegend)


    Hi so this is my php code to hide a specific category in my woocommerce shop page, however when I enter it into codesnippet plugin, it cannot activate, it kept showing the message

    Cannot redeclare function get_subcategory_terms

    Can someone please help, thank you!

    /**Show products only of selected category**/
    function get_subcategory_terms( $terms, $taxonomies, $args ) { $new_terms = array();
    $hide_category = array( 48 ); // Ids of the category you don’t want to display on the shop page
    // if a product category and on the shop page
    if ( in_array( ‘product_cat’, $taxonomies ) && !is_admin() && is_shop() ) { foreach ( $terms as $key => $term ) { if ( ! in_array( $term->term_id, $hide_category ) ) { $new_terms[] = $term; } } $terms = $new_terms; }
    return $terms;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @coinlegend

    Thanks for reaching out!

    I understand that you are using the code snippet above to hide a specific category on your Shop page, however, you are receiving the error message above, correct?

    This is a bit of a complicated topic that would need some customization to address. Unfortunately, custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any other questions related to development or custom coding, don’t hesitate to reach out to some of the great resources we have available for support. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:

    Meanwhile, I did some research and found these article/plugin could be a good starting point:

    Hope this helps!

    Thread Starter coinlegend

    (@coinlegend)

    Thank you, it’s just that the code seems to work fine when I put it in php directly, but it isn’t working properly when I put it in code snippet plugin.

    Hi,

    however when I enter it into codesnippet plugin, it cannot activate, it kept showing the message

    Cannot redeclare function get_subcategory_terms

    Hmm, this is odd, I was adding the snippet into my code snippets installation. This is the outcome:

    If the odd behavior is happening in Code Snippets, I recommend you to reach out to their dedicated forum ~ here.

    I hope this points you in the right direction.

    • This reply was modified 1 year, 10 months ago by Igor H.
    Thread Starter coinlegend

    (@coinlegend)

    Thank you, I will try asking in the code snippet forum.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Cannot redeclare function get_subcategory_terms’ is closed to new replies.