• Resolved mrloco

    (@mrloco)


    I used this code to hiding product categories in woocommerce.

    add_filter( 'get_terms', 'filter_get_terms', 10, 3 );
    function filter_get_terms( $terms, $taxonomies, $args ) {
        $new_terms = [];
    
        // if a product category and on the shop page
        if ( ! is_admin() ) {
            foreach ( $terms as $term ) {
                if ( ! in_array( $term-> slug, [ 'seinakellad', 'nastennye-chasy', 'wall-clock', 'juuksekammid', 'grebni-dlja-volos', 'hair-combs' ] ) ) {
                    $new_terms[] = $term;
                }
            }
    
            $terms = $new_terms;
        }
    
        return $terms;
    }

    After updating to PHP 8.2 I got this error:
    **
    Warning**: Attempt to read property “slug” on int in /data01/virt81820/domeenid/www.enjoythewoodestonia.ee/test/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()’d code on line 8

    So…whats the problem with that “slug” and how to fix it?

    Thanks!

    • This topic was modified 3 years, 6 months ago by mrloco.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @mrloco

    Thanks for reaching out!

    Firstly, I apologize for the delayed response.

    I understand that you received the error above after upgrading your PHP version to 8.2.

    These forums are meant for general support with the core functionality of WooCommerce itself. Since custom coding is outside our scope of support, I am leaving this thread open for a bit to see if anyone can chime in to help you out.

    For questions related to development and custom coding, your best bet is to ask on any of these channels for support. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, too.

    WooCommerce Developer Resources Portal
    WooCommerce Advanced Facebook group
    WooCommerce Community Forum
    WooCommerce Developer Slack Channel.
    – Hire a WooCommerce Expert

    Hope this helps!

    Thread Starter mrloco

    (@mrloco)

    Hi @xue28

    Thanks for answering. Maybe you can offer me some other way to resolve my problem: how to hide needed categories without deleting them?
    It is no matter, if some category empty or not, but sometimes i need to hide it from the frontend (woocommerce widget, category page etc).

    Saif

    (@babylon1999)

    Hello @mrloco,

    As mentioned this is not within our scope of support, but you can follow an easier approach with CSS.

    Let’s take this page as an example: https://enjoythewoodestonia.ee/toote-kategooria/aksessuaarid/

    Inspecting the element in the browser, you can see the class name is product-categories


    Link to image: https://d.pr/i/WtRfZe

    To hide the class, you can add the following code in Appernace > Customizer > Additional CSS.

    .product-categories {
    
    display: none;
    
    }

    If you have some page examples, you can share them here and we’ll help you write the snippet for it. 🙂

    To learn more about hiding page elements with CSS, you can check the following guide: https://css-tricks.com/comparing-various-ways-to-hide-things-in-css/

    Cheers!

    Thread Starter mrloco

    (@mrloco)

    @babylon1999
    Hi, thanks for answering! I have CSS to hide categories from Woo widget(like on your photo).
    My problem is, that the old CSS that does not work with PHP8.2 hides categories also from the Category page.
    For example Category “Home decorations”, there is a subcategory “wall-clock”. I hid “wall-clock” from the widget with CSS. But this category is still on the “Home decorations” category page.

    Photo

    • This reply was modified 3 years, 6 months ago by mrloco.

    Hi,

    After updating to PHP 8.2 I got this error:
    **
    Warning**: Attempt to read property “slug” on int in /data01/virt81820/domeenid/www.enjoythewoodestonia.ee/test/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()’d code on line 8

    You can ask at the Code Snippets forum for further assistance regarding the error.

    Feel free to let us know if there are any questions after that.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Problem with hiding categories with PHP 8.2’ is closed to new replies.