Tagged: cross sells, woocommerce
-
AuthorPosts
-
October 25, 2021 at 10:56 pm #1326399
Hi Support,
I am looking to increase the number of cross-sells displayed on the basket page to 12 products, the basket seems to be limited to 4. I tried the following woocommerce snippet but it doesn’t appear to work: https://docs.woocommerce.com/document/change-number-of-related-products-output/
Your help with this would be greatly appreciated.
Thanks
SeanOctober 26, 2021 at 8:18 am #1326447Hey MotiveAgency,
Thank you for the inquiry.
You can try this code in the functions.php file to adjust the columns and number of items in the upsells section.
add_action("after_setup_theme", function() { global $avia_config; $avia_config['shop_single_column'] = 12; // columns for related products and upsells $avia_config['shop_single_column_items'] = 12; // number of items for related products and upsells }, 10, 1);
If this doesn’t work, try to directly modify the avia_woocommerce_output_upsells function in the wp-content/themes/enfold/config-woocommerce/config.php file.
Best regards,
IsmaelOctober 26, 2021 at 10:08 am #1326461Hi Ismael,
Thank you for your quick response.
add_filter('woocommerce_cross_sells_total', 'avia_woocommerce_cross_sale_count'); add_filter('woocommerce_cross_sells_columns', 'avia_woocommerce_cross_sale_count'); function avia_woocommerce_cross_sale_count($count) { return 4; }
I found the above code in the config-woocommerce file as you mentioned which changing the return value to 12 solves my issue.
My question now is perhaps the code in the functions could be changed to target that value? Something like:
add_action("after_setup_theme", function() { global $avia_config; $avia_config['woocommerce_cross_sells_total'] = 12; // columns for related products and upsells $avia_config['woocommerce_cross_sells_columns'] = 12; // number of items for related products and upsells }, 10, 1);
The function didn’t work but you may have a better idea as to what it should be changed to.
Alternatively, is there a way I can include the wp-content/themes/enfold/config-woocommerce/config.php file in my child theme as an override?
Thank you for your help.
SeanOctober 27, 2021 at 5:41 am #1326601Hi,
Thank you for the update.
Did you try the hook that we provided above? It should adjust the value of the shop_single_column and the shop_single_column_items. You can also try to replace the after_setup_theme with the init hook.
Or just copy the whole avia_woocommerce_output_upsells function in the child theme’s functions.php file. You have to rename it.
function avia_woocommerce_output_upsells_modified($items = false, $columns = false) { global $avia_config; $output = ""; if(!$items) $items = 12; if(!$columns) $columns = 12; ob_start(); woocommerce_upsell_display($items,$columns); // 4 products, 4 columns $content = ob_get_clean(); if($content) { $output .= "<div class='product_column product_column_".$columns."'>"; //$output .= "<h3>".(__('You may also like', 'avia_framework'))."</h3>"; $output .= $content; $output .= "</div>"; } $avia_config['woo_upsells'] = $output; return $output; }
Remove the original hook, then register a new one.
// needs to be called after the "related product" function to inherit columns and product count remove_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_output_upsells', 21); add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_output_upsells_modified', 21);
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.