• Resolved bashiachuki

    (@bakoline)


    Now my 1st tab is Reviews on the product page and I need a function to move reviews to 2nd position and move Description to 1st position if the product has 0 reviews

    I searched everywhere and can’t find exactly this function, can you please help me out?

Viewing 3 replies - 1 through 3 (of 3 total)
  • /**
     * Reorder product data tabs if no reviews
     */
    function woo_reorder_tabs( $tabs ) {	
        // Get $product object
        global $product;
    	
        // Get total product Reviews
        $product_reviews = $product->get_review_count();
    	
        // No reviews found
        if ( $product_reviews == 0 ) {
            $tabs['description']['priority'] = 5; // Description first
            $tabs['reviews']['priority'] = 10; // Reviews second		
        }
    	
        return $tabs;
    }
    add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98, 1 );
    Thread Starter bashiachuki

    (@bakoline)

    @crslz Thanks for your reply but it doesn’t work.

    Here is my code related to tabs from my functions file

    /**
     * Woocommerce tabs default reviews-----------------------------------
     */
    
    add_filter( 'woocommerce_product_tabs', 'reordered_tabs', 98 );
    function reordered_tabs( $tabs ) {
        $tabs['reviews']['priority'] = 10; 
        $tabs['description']['priority'] = 20; 
     
        return $tabs;
    }
    
    /**
     * Add a custom tab Comparison and hide when empty
     */
    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
    function woo_new_product_tab( $tabs ) {
       global $post;
    
       if( get_post_meta( $post->ID, 'field_one', true ) || get_post_meta( $post->ID, 'comparison_product', true ) ){
        // Adds the new tab
    
        $tabs['features'] = array(
            'title'     => __( 'Comparison', 'stackoverflow' ),
            'priority'  => 30,
            'callback'  => 'woo_new_product_tab_content_comparision'
        );
       }
        return $tabs;
    
    }
    
    function woo_new_product_tab_content_comparision() {
        global $product;
        echo '<div class="div_center">';
          echo do_shortcode(get_post_meta($product->id, 'comparison_product', true));
          echo '</div>';
      // print_r($product);
      }

    Hi,

    can you change the code to the next and try?

    /**
     * Woocommerce tabs default reviews-----------------------------------
     */
    add_filter( 'woocommerce_product_tabs', 'reordered_tabs', 98 );
    function reordered_tabs( $tabs ) {
        // Get $product object
        global $product;
    
        global $post;
    	
        // Get total product Reviews
        $product_reviews = $product->get_review_count();
    	
        // No reviews found
        if ( $product_reviews == 0 ) {
            $tabs['description']['priority'] = 10; // Description first
            $tabs['reviews']['priority'] = 20; // Reviews second		
        } else {
            $tabs['reviews']['priority'] = 10; 
            $tabs['description']['priority'] = 20;
        }
    
        if( get_post_meta( $post->ID, 'field_one', true ) || get_post_meta( $post->ID, 'comparison_product', true ) ) {
            // Adds the new tab
    
            $tabs['features'] = array(
                'title'     => __( 'Comparison', 'stackoverflow' ),
                'priority'  => 30,
                'callback'  => 'woo_new_product_tab_content_comparision'
            );
        }
     
        return $tabs;
    }
    
    function woo_new_product_tab_content_comparision() {
        global $product;
        echo '<div class="div_center">';
        echo do_shortcode(get_post_meta($product->id, 'comparison_product', true));
        echo '</div>';
        // print_r($product);
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change product tabs order if no reviews’ is closed to new replies.