• Resolved Rosca Bogdan

    (@roscabgdn)


    Hy,
    I have a question regarding the output of yith_similar_products shortcode.
    Now the title of similar products is wraped in h2 tags. I want to modify the markup and add my own.
    Is there a way to do that?

    I see YITH_WRVP_Frontend function is called in class.yith-wrvp-frontend.php but I cannot override get_instance() in order to modify the content.

    Thx!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi,
    the right method to do this is to override class method similar_products() or to create your own shortcode. For example add on your theme’s functions.php this code

    if( function_exists('YITH_WRVP_Frontend')) {
    
    add_shortcode( 'custom_yith_similar_products', 'custom_yith_similar_products_function' );
    function custom_yith_similar_products_function(){
    	extract( shortcode_atts(array(
    				'posts_per_page' => get_option( 'yith-wrvp-num-products', '4' ),
    				'orderby' => 'rand',
    				'title'		=> get_option( 'yith-wrvp-section-title' )
    			), $atts ) );
    
    			$similar = YITH_WRVP_Frontend()->get_similar_product();
    
    			if( empty( $similar ) ) {
    				return '';
    			}
    
    			$args = apply_filters( 'yith_wrvp_similar_products_template_args', array(
    				'post_type'            => 'product',
    				'ignore_sticky_posts'  => 1,
    				'no_found_rows'        => 1,
    				'posts_per_page'       => $posts_per_page,
    				'orderby'              => $orderby,
    				'post__in'             => $similar
    			) );
    
    			$products = new WP_Query( $args );
    
    			ob_start();
    
    			if ( $products->have_posts() ) : ?>
    
    				<div class="woocommerce yith-similar-products">
    
    					<h2><?php echo $title ?></h2>
    
    					<?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(); ?>
    
    				</div>
    
    			<?php endif;
    
    			$content = ob_get_clean();
    
    			wp_reset_postdata();
    
    			return $content;
    }
    
    remove_action( 'woocommerce_after_single_product_summary', array( YITH_WRVP_Frontend(), 'print_shortcode' ), 30 );
    add_action( 'woocommerce_after_single_product_summary', 'print_custom_shortcode', 30 );
    function print_custom_shortcode(){
    	echo do_shortcode('[custom_yith_similar_products]');
    }
    
    }

    So you need only to change title tag as you wish.
    Let me know. Greetings.

    Thread Starter Rosca Bogdan

    (@roscabgdn)

    It`s working. Thank you for your support and quick answer.

    Maybe it will be a nice update if you decide to add a drop-down with allowed HTML tags so we can choose which tag wraps the title.
    Or maybe something like : <chosen_tag><span>Title</span></chosen_tag>. Front-end developers will love that ??

    Thank you again for your help!

    Plugin Author YITHEMES

    (@yithemes)

    Hi,
    thanks for this suggestion, the developer will consider this feature for next plugin update.
    Regards ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change shortcode output heading’ is closed to new replies.