• Resolved GrayHunter

    (@grayhunter)


    Hello,
    Probably a very simple question but I need some help with this, please.

    I need to show something only on the shop/category page, not on a product page. This code does not work in functions.php:

    if( !is_product_category() ) {
    }

    Please advise.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter GrayHunter

    (@grayhunter)

    Do I take it right, that there is no condition in WP & Woo letting me limit something only for a product page?

    Thread Starter GrayHunter

    (@grayhunter)

    Your link says the following:
    If you are looking for a way to check if you are on a product page in WooCommerce, you most likely think you should use WordPress single post conditional tag something like is_single( ).

    Unfortunately, this does not work with WooCommerce single page.

    Thread Starter GrayHunter

    (@grayhunter)

    Finally, I just solved the issue with CSS by hiding the items I do not need on the product page.
    But still it would be nice to know a better solution.

    lockoloop

    (@lockoloop)

    Saif

    (@babylon1999)

    Hello @lockoloop,

    Custom development is not within our scope of support there in the forums.

    Limiting the content display using CSS is the best way around this as you can use the category and shop page selectors.

    That said, if you’re working with something functional you can try something like this:

    /* Just a silly snippet to change the CSS of the Site header but only on the shop or category pages ?? */
    
      function make_some_changes()
    {
        if (is_shop() or is_product_category() )
        {
          ?> <style>
          .site-branding {
            background-color: red !important;
          }
          }
         
         </style> <?php
        }
    }
    
    add_action('wp_print_scripts', 'make_some_changes');

    In this example, I’m adding some CSS but you can change the logic to anything you want.

    Hope this helps!

    Thread Starter GrayHunter

    (@grayhunter)

    Hello @babylon1999,

    Thank you for the code, but it does not relate to a product page. If you could give us a code for a product page (not for an archive or a category) – that would be great since there is no such code anywhere, I’ve searched…

    Hi @grayhunter

    I understand that your looking for a custom code for the product page.

    As what Saif mentioned, these forums are meant for general support with the core functionality of WooCommerce itself. What you want to achieve is a bit complex and would require customization to do it. 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!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to check if current page is a Product Page?’ is closed to new replies.