• Resolved jaspejacobo

    (@jaspejacobo)


    Hi team,

    I want to edit the “no products found” message on a specific tag page only for guests, in this case ‘pulseras’. i.e. if the guest types a wrong reference on the search bar at the shop page, the default “no products found” mesage should show up.

    I found that the hook below is actually working as expected BUT rather than the tag page, it works in the shop page:
    shop page

    // Customise the message when no products found.
    add_action('wp_head', 'change_no_products_found_text');
    
    function change_no_products_found_text() {
        if (is_product_tag && !is_user_logged_in()) {
            // Remove the original code that uses the no-products-found.php template.
            remove_action('woocommerce_no_products_found', 'wc_no_products_found');
            // and add in my own code.
            add_action('woocommerce_no_products_found', 'no_products_found_new');
        }
    }
    
    function no_products_found_new() {
        ?>
        <div class="row products-loop products-grid with-ajax row-count-4" data-row-count="4">
    
            <h2><?php esc_html_e('No hemos encontrado productos', 'xstore-child'); ?></h2>
            <p><?php esc_html_e('Algunos productos son exclusivos para nuestros clientes', 'xstore-child'); ?></p>
            <p><a class="btn black medium" href="https://jaibor.com/registrarse/">
                    <span><?php esc_html_e('Solicita acceso para ver más', 'xstore-child'); ?></span>
                </a>
            </p>
            <?php echo do_shortcode('[products limit="4" tag="pulseras" orderby="date" ]'); ?>
        </div>
    
        <?php
    }

    I hope it makes sense.
    Thank you in advance
    Jacobo

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter jaspejacobo

    (@jaspejacobo)

    It seems like the
    is_product_tag
    conditional is not working.

    Plugin Support Daniyal Ahmed (a11n)

    (@daniyalahmedk)

    Hi there,

    Thanks for reaching out.

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Best,

    Thread Starter jaspejacobo

    (@jaspejacobo)

    Hi Daniyal,
    Did you give it a try? It is a basic function. I am missing the conditional which works for is_product_tag

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @jaspejacobo.

    Your code seems to work, but as far as I can see it returns the same new message for both tag page and also when doing a search query for shop/archive. At least in my test.

    I also understand that you would like the default message to show when queried in search, and the new message only for tag page? If so, then one possible workaround here would be to add a check to your second function to see if (!is_search()) { .. then add else { add_action('woocommerce_no_products_found', 'wc_no_products_found'); to return the default message.

    Something like this (untested):

    function no_products_found_new() { if (!is_search()) {
        ?>
        <div class="row products-loop products-grid with-ajax row-count-4" data-row-count="4">
    
            <h2><?php esc_html_e('No hemos encontrado productos', 'xstore-child'); ?></h2>
            <p><?php esc_html_e('Algunos productos son exclusivos para nuestros clientes', 'xstore-child'); ?></p>
            <p><a class="btn black medium" href="https://jaibor.com/registrarse/">
                    <span><?php esc_html_e('Solicita acceso para ver más', 'xstore-child'); ?></span>
                </a>
            </p>
            <?php echo do_shortcode('[products limit="4" columns="4" orderby="popularity" class="quick-sale" on_sale="true" ]'); ?>
        </div> 
    
        <?php
    } else {
    	add_action('woocommerce_no_products_found', 'wc_no_products_found');
    }

    Hopefully that helps you in the right direction.

    Cheers!

    Thread Starter jaspejacobo

    (@jaspejacobo)

    LEGEND @rynald0s ! WORKS !

    • This reply was modified 2 years, 5 months ago by jaspejacobo.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Edit no products found message on a specific tag page only’ is closed to new replies.