Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    you need to modify related.php template file.
    PATH: your-theme/woocommerce/single-product/related.php

    Change $args to,

    $args = apply_filters( 'woocommerce_related_products_args', array(
    		'post_type' => 'product',
    		'ignore_sticky_posts' => 1,
    		'no_found_rows' => 1,
    		'posts_per_page' => $posts_per_page,
    		'orderby' => $orderby,
    		'post__not_in' => array( $product->id ),
    		'tax_query' => array(
    			array(
    				'taxonomy' => 'product_cat',
    				'field' => 'id',
    				'terms' => $cats_array
    			),
    		)
    ) );

    where $cats_array is,

    $cats_array = array(0);
    // Get product categories
    $terms = wp_get_post_terms( $product->id, 'product_cat' );
    
    //Select only the category which doesn't have any children
    if( sizeof( $terms ) ){
    	foreach ( $terms as $term ) {
    		$children = get_term_children( $term->term_id, 'product_cat' );
    		if ( !sizeof( $children ) )
    			$cats_array[] = $term->term_id;
    	}
    }

    and remove/comment,

    $related = $product->get_related( $posts_per_page );
    if ( sizeof( $related ) == 0 ) return;

    In WooCommerce 2.3 +, you can use filter,

    add_filter( 'woocommerce_add_to_cart_message', 'custom_add_to_cart_message' );
    add_filter( '_add_to_cart_message', 'custom_add_to_cart_message' );
    function custom_add_to_cart_message( $message  ){
    return '';
    }
Viewing 2 replies - 1 through 2 (of 2 total)