Site logo

Archived topic

WooCommerce Upsells Ordering by ASC

5 replies · Started by Matthew on February 9, 2023

Viewing posts 1–6 of 6

Does GeneratePress allow setting of the ordering direction parameter when displaying WooCommerce Upsells?

I am trying to order Upsells by menu_order ascending. I have used the WooCommerce filter 'woocommerce_upsells_orderby' to set the 'menu_order' however WooCommerce doesn't provide a filter to set the query direction, any chance that GeneratePress does?

Hi there,

GP doesn't interfere ( where possible ) with what woo does.

I had a look to see how Woo displays the upsells.
And it uses the woocommerce_upsell_display() function.

Which i tracked to this:

https://github.com/woocommerce/woocommerce/blob/6ba45889b6847e69bda9bbe7cd53732b55fb578c/plugins/woocommerce/includes/wc-template-functions.php#L2086-L2126

And it has one main $args filter:

woocommerce_upsell_display_args

And it has an individual filter for the order -> woocommerce_upsells_order

Does that help ?

Hi David,

Thanks for looking into it.

My question would be when GeneratePress calls the woocommerce_upsell_display() function is there anyway to set the $order var to be 'ASC' instead of the default 'DESC'.

I am using the WooCommerce filter already to change the order_by parameter but cannot change the order parameter.

So I get my upsells shown in menu_order by back-to-front instead of front-to-back. I did have a look at the woocommerce_upsell_display function as it doesn't have a filter to changing the ordering.

GP doesn't make that callback.
Its made by the woo template
The only time GPP gets in the way is if the Customizer > Layout > Woocommerce options have it disabled, and then we simply unhook that function ie.

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );

I am not sure what the issue is, but there are the: woocommerce_upsell_display_args and the specific woocommerce_upsells_order filters ... do those not work ?

If they don't then you could:

1. Unhook the woocommerce_upsell_display

// remove the upsells action 
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );

2. Hook in a custom callback for it eg.:


add_action( 'woocommerce_after_single_product_summary', 'get_custom_upsell_display', 15 );
function get_custom_upsell_display() {
// woocommerce_upsell_display( $limit = '-1', $columns = 4, $orderby = 'rand', $order = 'desc' )
    woocommerce_upsell_display( -1, 4, 'menu_order', 'asc' );
}

David,

I am so sorry, you are correct there is the 'woocommerce_upsells_order' filter. I totally did not see that!!!

My apologies for wasting your time.

Many Kind Regards,

Matt

No apologies necessary :) Glad to be of help!

This archived topic is closed to new replies.