Home › Forums › WoodMart support forum › Limit number of products for compare
Limit number of products for compare
- This topic has 9 replies, 2 voices, and was last updated 5 years ago by
Artem Temos.
-
AuthorPosts
-
September 16, 2020 at 11:50 am #226675
marmalabcreativeParticipantHello there,
I would like to limit the compare product to 3. How can be done this in current compare.php? or somewhere else?
Thanks
September 16, 2020 at 12:16 pm #226689
Artem TemosKeymasterHi,
Try to add the following PHP code snippet to the child theme functions.php file to do this
function woodmart_get_compared_products_table() { $products = woodmart_get_compared_products_data(); $fields = woodmart_get_compare_fields(); $empty_compare_text = woodmart_get_opt( 'empty_compare_text' ); ?> <div class="woodmart-compare-table"> <?php if ( ! empty( $products ) ) { array_unshift( $products, array() ); foreach ( $fields as $field_id => $field ) { if ( ! woodmart_is_products_have_field( $field_id, $products ) ) { continue; } ?> <div class="woodmart-compare-row compare-<?php echo esc_attr( $field_id ); ?>"> <?php $i = 0; ?> <?php foreach ( $products as $product_id => $product ) : ?> <?php if ( $i > 3 ) : ?> <?php continue; ?> <?php endif; ?> <?php if ( ! empty( $product ) ) : ?> <div class="woodmart-compare-col compare-value" data-title="<?php echo esc_attr( $field ); ?>"> <?php woodmart_compare_display_field( $field_id, $product ); ?> </div> <?php else: ?> <div class="woodmart-compare-col compare-field"> <?php echo esc_html( $field ); ?> </div> <?php endif; ?> <?php $i++; ?> <?php endforeach ?> </div> <?php } } else { ?> <p class="woodmart-empty-compare woodmart-empty-page"> <?php esc_html_e('Compare list is empty.', 'woodmart'); ?> </p> <?php if ( $empty_compare_text ) : ?> <div class="woodmart-empty-page-text"><?php echo wp_kses( $empty_compare_text, array('p' => array(), 'h1' => array(), 'h2' => array(), 'h3' => array(), 'strong' => array(), 'em' => array(), 'span' => array(), 'div' => array() , 'br' => array()) ); ?></div> <?php endif; ?> <p class="return-to-shop"> <a class="button" href="<?php echo esc_url( wc_get_page_permalink( 'shop' ) ); ?>"> <?php esc_html_e( 'Return to shop', 'woodmart' ); ?> </a> </p> <?php } ?> </div> <?php }
Regards
September 16, 2020 at 12:55 pm #226723
marmalabcreativeParticipantHello Artem,
The function is only hiding the products that are extra e.g. 4th, 5th, etc. But I can still add products to compare and I see on the menu bar that there are more than 3 products for compare.
September 16, 2020 at 1:01 pm #226726
Artem TemosKeymasterSorry, but there is no option in our theme to limit the number of products in the compare completely, unfortunately.
September 16, 2020 at 1:11 pm #226738
marmalabcreativeParticipantAny plans to add it in the future?
September 16, 2020 at 1:49 pm #226749
Artem TemosKeymasterCurrently, we don’t have such plans. We will consider this as a feature request for our future updates.
September 16, 2020 at 2:26 pm #226755
marmalabcreativeParticipantIn this case:
Can you point me which file I can edit on my own in order to limit adding items to 3?
September 16, 2020 at 2:31 pm #226757
Artem TemosKeymasterSorry, but there is no such mechanism that you can simply change to 3. We don’t have instruction about this additional customization.
September 17, 2020 at 4:30 am #226855
marmalabcreativeParticipantI understand that. I just ask which if you suggest me to edit in order to do it myself, like compare.php and/or function.php, etc..?
September 17, 2020 at 6:12 am #226885
Artem TemosKeymasterIt may require a lot of files to customize. It is not just a single place and we don’t have a complete instruction, unfortunately.
-
AuthorPosts
- You must be logged in to create new topics. Login / Register