• Resolved karyls

    (@karyls)


    My goal is to remove Related Products if I am using Upsells on a product page.

    I do not know php but have common sense.

    I found some code which removes the Related Products, however my problem is that it duplicates 3 of the Upsells at the bottom. On the page I linked to(https://bit.ly/2noW6Wm), there should only be 6 upsells products. ‘You may also like…’ begins again.

    I have disabled plugins, looked for ‘related posts/products’ settings to no avail. When I take out the code I used below, the problem goes away so I assume the replication is coming from the code. I could be wrong of course.

    Any advice on how to get rid of the duplicate listing? Thank you in advance, I’ve tried and can’t seem to get it right or come up with an alternative.

    ————————————-
    this was added to my functions.php

    // REMOVE RELATED IF UPSELLS

    remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_upsell_display’, 15 );
    remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_related_products’, 20 );

    add_action( ‘woocommerce_after_single_product_summary’, ‘related_upsell_products’, 15 );

    function related_upsell_products() {
    global $product;

    if ( isset( $product ) && is_product() ) {
    $upsells = $product->get_upsells();

    if ( sizeof( $upsells ) > 0 ) {
    woocommerce_upsell_display();
    } else {
    woocommerce_upsell_display();
    woocommerce_output_related_products();
    }
    }
    }

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hodwy!

    There’s nothing in that code that would make it run twice.

    Do you have any caching plugins installed? If so, please purge your caches and reload the page, to see if the duplicated one is still present.

    Cheers!

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Howdy!

    We haven’t heard back from you in a while, so I’m going to go ahead and mark this thread as resolved. If you have any other questions please start a new thread.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Remove Related if Using Upsells’ is closed to new replies.