I need a function to hide out of stock upsell products
Budget: $10 – $30 USD
Hi,
i'm using Api to get upsell products, it is using get_upsell_ids
I need a function to hide the out of stock upsells
i have a similar function working very well for search:
// Change search function globally to search only post, page and portfolio post types
function prefix_limit_post_types_in_search( $query ) {
if (!is_admin() && $query->is_search ) {
$query->set( 'post_type', array( 'product' ) );
$query->set( 'meta_query', array(
array(
'key' => '_stock_status',
'value' => 'instock'
),
) );
}
return $query;
}
add_filter( 'pre_get_posts', 'prefix_limit_post_types_in_search' );
i need something similar for upsells, please do not forget i'm using API i'm ot talking about the website, the function should target get_upsell_ids
i'm using Api to get upsell products, it is using get_upsell_ids
I need a function to hide the out of stock upsells
i have a similar function working very well for search:
// Change search function globally to search only post, page and portfolio post types
function prefix_limit_post_types_in_search( $query ) {
if (!is_admin() && $query->is_search ) {
$query->set( 'post_type', array( 'product' ) );
$query->set( 'meta_query', array(
array(
'key' => '_stock_status',
'value' => 'instock'
),
) );
}
return $query;
}
add_filter( 'pre_get_posts', 'prefix_limit_post_types_in_search' );
i need something similar for upsells, please do not forget i'm using API i'm ot talking about the website, the function should target get_upsell_ids