Okay
  Public Ticket #3408042
Upsells products
Closed

Comments

  •  45
    Clara started the conversation

    Hi,

    I tried to remove the upsells products by writing the following piece of code in the functions.php and none of the two methods worked.

    // Salient function
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_upsells', 21 );

    // WooCommerce function
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );


    What should I do to remove them with PHP if none of those work?

    Also, I would like to change the number of columns displayed. I tried the following:

    add_filter( 'woocommerce_upsell_display_args', 'change_number_related_products', 99999 );
    function change_number_related_products( $args )
    {
        $args['columns'] = 2; 
        return $args;
    }

    This didn't work either. What should I do to have only two columns for my upsells carousel?

    BR,

    Clara.

  •  279
    Noah replied

    Hi Clara,

    Thanks for reaching out.

    The upsells can be removed from the following file:

    salient\nectar\helpers\woocommerce.php 

    Comment out line 717

    The function woocommerce_output_upsells is responsible for showing the upsells and you can alter it to output what you want.

    Hope you can work from there.

    Cheers.
    Noah

  •  45
    Clara replied

    Is there any another way to remove it than overriding this file? Just using the functions.php with hooks (like remove_action) won't do the trick?

    Also, I copied/pasted this function (woocommerce_output_upsells) in my functions.php to change the number of columns, by changing "4" by "2" at line 731. It indeed changed the CSS class "columns-4" to "columns-2" but nothing changed on the frontend. Also, you can see that data-n-desktop-columns still equals to 4.

    `<ul class="products columns-2 generate-markup flickity-enabled is-draggable" data-n-lazy="1" data-rm-m-hover="1" data-n-desktop-columns="4" data-n-desktop-small-columns="3" data-n-tablet-columns="3" data-n-phone-columns="2" data-product-style="minimal">`

    Do you know how to fix this?

    BR,

    Clara


  •  8,839
    Tahir replied

    Hey Again,

    If you dont want to output anything you can place an empty function in the Child Theme "functions.php" file like below:

    function woocommerce_output_upsells() {
    }
    

    Thanks.


    ThemeNectar Support Team 

  •  45
    Clara replied

    No, I want to output something. Actually, I changed the location of the upsells with this, which works well:

    add_action( 'woocommerce_single_product_summary', 'woocommerce_output_upsells', 55 );

    But now, I want to be able to remove the upsells that are still at their initial location, AND I want to have 2 columns instead of the initial 4.

    Do you know what I mean? I'm sorry if I'm not clear.

  •  279
    Noah replied

    Hi there,

    To remove the upsells that are still at the original location then comment out line  717 as earlier recommended.

    The HTML for the upsells is from woocommerce and the theme does not override it.

    The theme uses the woocommerce file wp-content\plugins\woocommerce\templates\single-product\up-sells.php to show the upsells.

    To change the layout can override that file by placing it in the theme at 

    salient/woocommerce/single-product/up-sells.php 

    And then change the output to what you need.
    Hope this helps.

  •  45
    Clara replied

    Hi Noah,

    I had a look at the up-sells.php file, and this file doesn't manage the number of columns.

    I managed to make it work with the following piece of code: https://hirejordansmith.com/change-upsell-products-per-row-woocommerce/

    BR,

    Clara.

  •  279
    Noah replied

    Hi Clara,

    Great to hear to fix this up.

    Cheers, and good luck with your site.