Home › Forums › Themes Support › Claue › releted product showing incorrect
- This topic has 7 replies, 2 voices, and was last updated 4 years, 3 months ago by Harry.
-
AuthorPosts
-
-
September 21, 2020 at 8:18 pm #38598artimizationSupport Expired
Hello
i want to show related products for the same category like (Casio General) so all related product showing (Casio General) category
Screen shot: https://prnt.sc/ul4vuu
Can you give me the solution
Thanks
omer
-
September 21, 2020 at 11:04 pm #38601HarrySupport Expired
Hi Omer,
Please create file related.php in claue-child/woocommerce/single-product/related.php
and put the code to this file follow this topic https://stackoverflow.com/questions/26316952/woocommerce-only-show-related-products-from-same-subcategory
<?php /** * Related Products * * This template can be overridden by copying it to yourtheme/woocommerce/single-product/related.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates * @version 3.9.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; } global $product, $woocommerce_loop; if ( empty( $product ) || ! $product->exists() ) { return; } if ( ! $related = $product->get_related( $posts_per_page ) ) { return; } // Get ID of current product, to exclude it from the related products query $current_product_id = $product->get_id(); $cats_array = array(0); // get categories $terms = wp_get_post_terms( $product->id, 'product_cat' ); // select only the category which doesn't have any children foreach ( $terms as $term ) { $children = get_term_children( $term->term_id, 'product_cat' ); if ( !sizeof( $children ) ) $cats_array[] = $term->term_id; } $args = apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'post__not_in' => array( $current_product_id ), // exclude current product 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $cats_array ), ) )); $products = new WP_Query( $args ); $woocommerce_loop['name'] = 'related'; $woocommerce_loop['columns'] = apply_filters( 'woocommerce_related_products_columns', $columns ); if ( $products->have_posts() ) : ?> <section class="related products"> <?php $heading = apply_filters( 'woocommerce_product_related_products_heading', __( 'Related products', 'woocommerce' ) ); if ( $heading ) : ?> <h2><?php echo esc_html( $heading ); ?></h2> <?php endif; ?> <?php woocommerce_product_loop_start(); ?> <?php while ( $products->have_posts() ) : $products->the_post(); ?> <?php wc_get_template_part( 'content', 'product' ); ?> <?php endwhile; // end of the loop. ?> <?php woocommerce_product_loop_end(); ?> </section> <?php endif; wp_reset_postdata();
Kind regards
Harry
Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio -
September 22, 2020 at 9:13 pm #38628artimizationSupport Expired
hello,
Above code working fine but the issue is all product showing in grid not in carousel slider,
You can see the video:
https://drive.google.com/file/d/1s9MIX8dmFUDVz-SubT8fGDPsBkKHI8iF/view
I want to show product in carousel slider, can you guide me what should i do.
Thank for your support
Regards
Omer
-
September 23, 2020 at 10:46 pm #38631artimizationSupport Expired
Hello.
Any update for me Thankyou
Regards
omer
-
September 23, 2020 at 11:59 pm #38632HarrySupport Expired
Hi,
Please try change all code by below code
<?php /** * Related Products * * This template can be overridden by copying it to yourtheme/woocommerce/single-product/related.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates * @version 3.9.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; } global $product, $woocommerce_loop; if ( empty( $product ) || ! $product->exists() ) { return; } if ( ! $related = $product->get_related( $posts_per_page ) ) { return; } // Get ID of current product, to exclude it from the related products query $current_product_id = $product->get_id(); $cats_array = array(0); // get categories $terms = wp_get_post_terms( $product->id, 'product_cat' ); // select only the category which doesn't have any children foreach ( $terms as $term ) { $children = get_term_children( $term->term_id, 'product_cat' ); if ( !sizeof( $children ) ) $cats_array[] = $term->term_id; } $args = apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'post__not_in' => array( $current_product_id ), // exclude current product 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $cats_array ), ) )); $products = new WP_Query( $args ); $woocommerce_loop['name'] = 'related'; $woocommerce_loop['columns'] = apply_filters( 'woocommerce_related_products_columns', $columns ); if ( $products->have_posts() ) : ?> <section class="related products"> <?php $heading = apply_filters( 'woocommerce_product_related_products_heading', __( 'Related products', 'woocommerce' ) ); if ( $heading ) : ?> <h2><?php echo esc_html( $heading ); ?></h2> <?php endif; ?> <?php woocommerce_product_loop_start(); ?> <div class="jas-carousel" data-slick='{"slidesToShow": <?php echo (int) $limit; ?>,"slidesToScroll": 1,"responsive":[{"breakpoint": 1024,"settings":{"slidesToShow": 3}},{"breakpoint": 480,"settings":{"slidesToShow": 2}}]<?php echo ( is_rtl() ? ',"rtl":true' : '' ); ?>}'> <?php foreach ( $related_products as $related_product ) : $post_object = get_post( $related_product->get_id() ); $GLOBALS['post'] =& $post_object; setup_postdata( $post_object ); wc_get_template( 'content-product.php' ); endforeach; ?> </div> <?php woocommerce_product_loop_end(); ?> </section> <?php endif; wp_reset_postdata();
Kind regards
Harry
Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio -
September 24, 2020 at 5:54 pm #38636artimizationSupport Expired
hello,
the above code you given its not working. product showing in carousel slider on the page load once page fully load products gone. also product not showing for the same category.
https://drive.google.com/file/d/1F3VN-LSfuGiX_n7GSsAiUAoj1s4XpXxM/view
Please check the video, or i give you ftp access to fix this part ?
Reagrds
Omer
-
September 25, 2020 at 12:09 am #38639HarrySupport Expired
Hi,
This issue need advance PHP skill, please hire expert at https://bit.ly/2Loo6ke to help you customize.
Kind regards
Harry
Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio -
September 25, 2020 at 12:19 am #38641HarrySupport Expired
You can try some plugins https://wordpress.org/plugins/woo-custom-related-products/ or https://wordpress.org/plugins/wt-woocommerce-related-products/
Kind regards
Harry
Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio
-
-
AuthorPosts
You must be logged in to reply to this topic.