adjust/fix related products
Budget: $10 – $30 USD
hey
i have catgory on the site not showing related product, theme dev answer:
Default the related product will be shown randomly. Example: Your product has 100 related products. It will random them and get 6 or 7 products ( based on the number of products that you set in the $args ). Sometimes it will pick up the right product that is out of stock. So some products do not display the related product.
i have added this to fix others catgory and its worked will i have one that not working need help with that
add_filter( 'woocommerce_related_products', 'exclude_oos_related_products', 10, 3 );
function exclude_oos_related_products( $related_posts, $product_id, $args ){
$out_of_stock_product_ids = (array) wc_get_products( array(
'status' => 'publish',
'limit' => -1,
'stock_status' => 'outofstock',
'return' => 'ids',
) );
$exclude_ids = $out_of_stock_product_ids;
return array_diff( $related_posts, $exclude_ids );
}
i have catgory on the site not showing related product, theme dev answer:
Default the related product will be shown randomly. Example: Your product has 100 related products. It will random them and get 6 or 7 products ( based on the number of products that you set in the $args ). Sometimes it will pick up the right product that is out of stock. So some products do not display the related product.
i have added this to fix others catgory and its worked will i have one that not working need help with that
add_filter( 'woocommerce_related_products', 'exclude_oos_related_products', 10, 3 );
function exclude_oos_related_products( $related_posts, $product_id, $args ){
$out_of_stock_product_ids = (array) wc_get_products( array(
'status' => 'publish',
'limit' => -1,
'stock_status' => 'outofstock',
'return' => 'ids',
) );
$exclude_ids = $out_of_stock_product_ids;
return array_diff( $related_posts, $exclude_ids );
}