• Resolved cshinkin

    (@cshinkin)


    Hi all. I have an action within functions.php that posts custom text to all product pages. However I now have an extra product template added alongside the default one and wish the same text to not appear. Having huge trouble working how to exclude that text from the new template.

    • This topic was modified 1 year, 2 months ago by cshinkin.
    • This topic was modified 1 year, 2 months ago by cshinkin.
    • This topic was modified 1 year, 2 months ago by cshinkin.

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • What does the code you currently have look like?

    Thread Starter cshinkin

    (@cshinkin)

    You would have to check there in the function in which context it is called. If you only execute the new product template for certain products, you could check this in the following way:

    add_action( 'woocommerce_single_product_summary', 'promo_alert', 20 );
    function promo_alert() {
        $post = get_queried_object();
        $product = wc_get_product($post->ID);
        if( in_array($product->get_id(), [42]) ) {
            return;
        }
        echo '<strong>WORLDWIDE SHIPPING rates...  ...notifications.</i><hr>';
    }

    In the example, the product with ID 42 is excluded from displaying the hint.

    Unfortunately I don’t know how you assign the template to the products. If necessary, you can also use this as a criterion by accessing the product object.

    Thread Starter cshinkin

    (@cshinkin)

    Seems like you are on the right track and thank you for the prompt replies. Cant get it to run yet as:

    Parse error: syntax error, unexpected token “&”, expecting “)” in C:\Users… …functions.php

    • This reply was modified 1 year, 2 months ago by cshinkin.
    Thread Starter cshinkin

    (@cshinkin)

    Oops take that back error was because I copied your script from the email rather than here. That works. Thank you so much its very much appreciated here.

    Glad if I could help. When you’ve finished implementing it, feel free to set the topic to solved.

    Thread Starter cshinkin

    (@cshinkin)

    Thank you once again sir could never have worked that out in that way myself. I am learning though 🙂

    • This reply was modified 1 year, 2 months ago by cshinkin.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding template related actions’ is closed to new replies.