PHP Snippet: Woocommerce Reviews as Shortcode

Are you using the Flatsome theme for your WooCommerce website and want to display product reviews in a shortcode?

With this tutorial, you’ll learn how to easily add a custom PHP snippet to your Flatsome theme and create a shortcode to showcase the reviews of the current product. By following these step-by-step instructions, you’ll be able to enhance your product pages and provide valuable social proof to your customers. Let’s get started!

  1. Access your WordPress admin dashboard.
  2. Then, Go to “Appearance” -> “Editor”. 
  3. In the right-hand sidebar, locate and click on “Theme Functions (functions.php)”.
  4. Scroll down to the bottom of the “Theme Functions” file.
  5. Add the following PHP snippet at the end of the file:
// Return a review shortcode of a Woocommerce product

add_shortcode( 'product_reviews', 'display_product_reviews_shortcode' );

function display_product_reviews_shortcode( $atts ) {
    global $post;
    
    if ( empty( $atts ) ) return '';
    
    $product_id = $post->ID;
    
    $comments = get_comments( 'post_id=' . $product_id );
    
    if ( ! $comments ) return '';
    
    $html = '<div class="woocommerce-tabs"><div id="reviews"><ol class="commentlist">';
    
    foreach ( $comments as $comment ) {
        $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
        $html .= '<li class="review">';
        $html .= get_avatar( $comment, '40' );
        $html .= '<div class="comment-text">';
        if ( $rating ) $html .= wc_get_rating_html( $rating );
        $html .= '<p class="meta"><strong class="woocommerce-review__author">';
        $html .= get_comment_author( $comment );
        $html .= '</strong> - <time class="woocommerce-review__published-date" datetime="' . get_comment_date( 'c', $comment ) . '">' . get_comment_date( '', $comment ) . '</time></p>';
        $html .= '<div class="description">';
        $html .= $comment->comment_content;
        $html .= '</div></div>';
        $html .= '</li>';
    }
    
    $html .= '</ol></div></div>';
    
    return $html;
}
  1. Click the “Update File” button to save the changes.
  2. Now, you can add the [product_reviews id=""] shortcode to any page or post where you want to display the product reviews. Edit the page or post where you want to add the shortcode.
  3. In the editor, place your cursor at the desired location to insert the shortcode.
  4. Enter [product_reviews id=""] at that location.
  5. Update or publish the page or post.

The provided PHP snippet adds a shortcode that will display the product reviews specific to the current product being viewed. The shortcode can be added to any page or post content using the [product_reviews id=""] shortcode.

Please note that it’s important to always make a backup of your theme files before making any changes.

Best WooCommerce Themes for Your Online Shop in 2023

Do you need the top WooCommerce themes?

The most popular WordPress eCommerce plugin is WooCommerce, which you can use to build an online store. Many themes created expressly for WooCommerce websites are available. We’ll provide our hand-selected selection of the top WooCommerce themes for your online business in this article.

What Are My Options for the Best WooCommerce Theme?

The WooCommerce plugin is meant to function with the majority of WordPress themes. However as a proprietor of an online organization, you’ll require a theme that prioritizes functions and choices connected to eCommerce.

To choose the finest WooCommerce theme, consider the following advice:

  1. Adaptable and simple to use: A WooCommerce theme may contain a ton of functionality, but it should also be adaptable and simple for new users to utilize. Look for a theme that includes adequate documentation for your use.
  2. Operate seamlessly with add-ons and extensions: WooCommerce has hundreds of free and paid plugins. The extensions and add-ons should all function well with the ideal eCommerce theme.
  3. SEO-friendly: You may increase traffic by using WooCommerce themes with built-in SEO optimization. Also, higher traffic equals more purchases on an e-commerce website.
  4. WordPress plugin compatibility: WooCommerce is a stand-alone plugin for WordPress, and your theme MUST play well with it. To give your online store further capabilities, the theme you select must also work with other WooCommerce plugins.
  5. Design that adapts: The majority of your consumers will browse your website on mobile smartphones, so make it responsive. The theme you select need to be completely mobile friendly and appealing across a range of gadgets and screen sizes.
  6. Integration of a page builder: Building a WooCommerce website with hundreds of products takes time. Drag-and-drop page builders let you quickly design personalized product pages.
  7. Optimization for speed: Slow eCommerce websites are bad for online enterprises. Choose a WooCommerce theme with a quick performance and minimal page load time.
  8. Live alerts: Setting up live sales notifications for WooCommerce will be made simple by a suitable WooCommerce theme.

Having learned how to pick the best WooCommerce theme, let’s look at our professional picks for the top themes below.

Outstanding WooCommerce Themes

This is where you need to be right now if you want to get all the best WooCommerce themes in one location. Choose one from the list of the top WooCommerce themes we’ve compiled below to launch your online store.

1. Astra Woocommerce Theme

The WordPress eCommerce theme Astra WooCommerce is quick and light. It’s designed exclusively to increase your sales on websites using WooCommerce. Without writing a single line of code, you can easily change this theme.

Features:

  • Rapid product vie
  • Options for an infinite scroll gallery
  • Purchasing options
  • Product listing
  • Grid options
  • plus more

Start using the Astra WooCommerce theme right away!

2. Flatsome Woocommerce Theme

A WordPress theme with a ton of features and versatility, Flatsome is ideal for building an e-commerce website. It has an intuitive interface that makes it simple to set up and maintain your online store and is built on the well-known WooCommerce framework. A drag-and-drop page builder, endless portfolio layouts, advanced product filtering, and other strong features are included in the theme’s long list of highly configurable features. Also, it has a potent live search engine that makes it easy for shoppers to find products. Flatsome is, all things considered, a fantastic theme for building an eCommerce website with outstanding functionality and a user-friendly design.Among its features:

  • Drag and Drop Page Builder
  • Limitless portfolio layouts
  • Advanced product filtering
  • Live search functionality
  • Responsive design
  • SEO optimization
  • WooCommerce compatibility
  • Also, there are product variations and image swaps.

The Flatsome WooCommerce theme can be used right away.

3. Neve

Neve is a multi-purpose theme that looks great on both mobile and desktop. The Customizer provides a plethora of layout options, making it simple to adapt to any type of online store. The WooCommerce Booster provides additional settings for controlling the appearance of your store pages. Even better, Neve loads quickly and is compatible with the majority of page builders.

Features:

  • Lightweight and quic
  • AMP compatible
  • Translation ready
  • Page builder compatible
  • 80+ starter site templates
  • Option for white labeling
  • WooCommerce Accelerator

Download Neve now and get started!

4. SeedProd

SeedProd is an excellent choice if you’re running WooCommerce on your website and want to customize the design.

This powerful website builder assists business owners in creating sleek, professional-looking web pages without the need for a developer. It’s incredibly simple to use; start with one of the many pre-made themes and customize it with the drag-and-drop visual editor.

SeedProd also fully supports WooCommerce, allowing you to create custom shop pages, shopping carts, and checkout pages, among other things.

Features:

  • Visual theme builder with drag-and-drop functionality
  • 150+ page templates and 15+ themes
  • WooCommerce custom blocks
  • Pages for coming soon and maintenance mode are built-in
  • Quick and easy to use on mobile devices
  • Integrate with email marketing services for sales, drip campaigns, and cart abandonment.
  • And there’s more…

Begin using SeedProd right away.

5. Botiga

Botiga is a modern, free eCommerce theme from aThemes. It’s optimized for performance, mobile responsive, and packed with customization options to help your online business stand out.

Features:

  • Product card listings that can be customized
  • Styles for the cart, product gallery, and checkout pages
  • Product recommendations and product search functionality
  • Wishlist functionality for performance and search engine optimization
  • And there’s more…

Begin using Botiga today!

6. OceanWP

OceanWP is a free WordPress multipurpose theme. It comes with multiple WooCommerce sites that you can import with the 1-click demo content importer to rapidly construct an online store.

Features:

  • Quick page loading
  • Built-in SEO
  • Translation ready
  • Premium addons
  • Page builder compatibility
  • And much more…

Get started with OceanWP right away!

7. Divi

Divi is a popular page builder and WordPress theme. Smart visual controls and built-in features make it simple to personalize. This theme has several design choices, inline text editing, layout adjustments, and other features.

The Divi theme includes a layout bundle and hundreds of WooCommerce templates to help you design your online store.

Features:

  • Font and text formatting
  • Expert code editing
  • Product filtration
  • Options for background images
  • Designs that are already efficient
  • And even more…

Begin using Divi now!

8. Ultra

Ultra is a strong multipurpose WordPress theme. It includes a pre-built WooCommerce website with demo content. This structure makes it simple to create store pages, product pages, and product categories.

Features:

  • Layouts that have already been designed
  • Themify creator
  • Pre-installed add-ons
  • Giant menu with section scrolling
  • And there’s more…

Get started with Ultra right away!

9. Online Shop Pro

Online Store Pro is a fantastic Woocommerce theme for setting up an online shop. It is simple to use and configure, and it has a modern, professional appearance. It has a lot of features that make it an excellent choice for starting an online business. The following are the five characteristics of the Online Store Pro Woocommerce theme:

  • Responsive design: The theme is completely responsive and looks fantastic on all devices.
  • Product page customization: The product page may be easily customized with many choices such as product description, reviews, similar items, and more.
  • Several payment gateways: You may select from a variety of payment gateways such as PayPal, Stripe, and others.
  • Several layouts: The theme includes several layouts from which to build the ideal store.

Get it today and begin building your online business.

10. Storefront

Storefront is a fantastic Woocommerce theme that will assist you in creating a gorgeous, modern, and professional website. Its sleek and modern design allows you to simply personalize it to appear exactly as you want it to. Here are some of its characteristics:

  • A mobile-friendly design that looks amazing on any device
  • Easily customizable with many color possibilities
  • Adaptable homepage design
  • Compatibility with popular plugins
  • Integrated SEO optimization

Download it right away and start building your ideal store!

11. Shoptimizer

Shoptimizer is an outstanding Woocommerce theme that greatly simplifies the process of opening an online store. It has a variety of features that make it an excellent pick for anybody wishing to build a slick and modern website.

Shoptimizer is meant to give lightning fast page loading times, ensuring your consumers have a seamless and delightful buying experience.

  • Simple Customization Options: The theme has an easy-to-use customization tool that makes modifying the design of your store simple and uncomplicated.
  • Mobile-Friendly Design: Shoptimizer’s responsive design guarantees that your store appears fantastic on all devices.
  • Built-in SEO: Shoptimizer includes a number of SEO tools that help to ensure your business is easily found on search engines.
  • Third-Party Tool Support: Shoptimizer makes it simple to connect third-party solutions like email marketing and analytics.

Download Shoptimizer today and start growing your company!

12. Velure

The Velure Woocommerce theme is ideal for anybody seeking a modern, minimalistic, and attractive online business. It has the following features:

  • A simple, attractive design with simple modification possibilities
  • Supported by all major browsers and mobile devices
  • WooCommerce is fully integrated.
  • Design that is fully responsive and mobile ready
  • Simple page builder

Purchase Velure now and begin selling immediately!

13. ShopIsle Pro

ShopIsle Pro Woocommerce theme is a beautifully designed, flexible, and user-friendly theme for businesses to create an amazing e-commerce website. The theme is fully compatible with WooCommerce and offers plenty of customization options to let you create the perfect website for your business.

Features:

  • Responsive design
  • Drag and drop page builder
  • Advanced WooCommerce integration
  • Multiple slider options
  • Flexible and user-friendly

Start your e-commerce journey today with ShopIsle Pro!

How Do I Expand My WooCommerce Store?

In order to maximize your sales and build customer loyalty, there are many strategies you can use. Let’s get started!

  1. Add more products and categories. Invest in high-quality product photography and descriptions to ensure customers can find what they’re looking for.
  2. Increase customer engagement with new customer loyalty programs and promotions.
  3. Leverage customer reviews to build trust and credibility.
  4. Implement upselling and cross-selling techniques to increase average order value.
  5. Utilize email marketing campaigns to keep customers informed of new products and promotions.
  6. Expand your customer base by utilizing social media channels to engage and attract new customers.
  7. Increase your store’s visibility with SEO optimization and link-building strategies.
  8. Utilize retargeting campaigns to reach past customers and convert them into repeat buyers.
  9. Invest in a professional website design to create a user-friendly and aesthetically pleasing experience for customers.
  10. Utilize digital payment options to make it easier for customers to purchase.

Remove Additional Information Tab @ Single Product

On the single product page, the “Additional Information” tab is a little unpleasant and, to be honest, very worthless.

There are 2 straightforward ways to “hide” it or remove it entirely: a CSS trick and a PHP fix. You can type the code in your preferred style but obviously, PHP is a better solution!

Always keep in mind that PHP is superior to CSS since PHP prevents the element from loading while CSS loads the element and subsequently hides it.

PHP Snippet

add_filter( 'woocommerce_product_tabs', 'remove_product_tabs', 9999 );

function remove_product_tabs( $tabs ) {
unset( $tabs['additional_information'] ); 
return $tabs;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete “?>” if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files.

Alternative Method to Hide Additional Information tab

I made the decision to hunt for a dependable plugin that accomplishes the same goal because I know that many readers would want to code but aren’t completely comfortable doing so.

I advise using the YITH WooCommerce Tab Manager plugin in this situation. You can remove basic tabs like “Reviews” and “Description,” but you can also add your own, make tabs display or hide depending on a product ID or category, print any material inside the new tabs like custom shortcodes, and do a lot more.

Reinstall Woocommerce Missing Pages

Millions of people utilize the potent e-commerce platform Woocommerce worldwide. It offers a simple way to produce, manage, and sell things online and is an open-source platform. Yet, there are a number of reasons why the Woocommerce pages could disappear occasionally. If this occurs, you will need to reinstall the Woocommerce plugin in order to restore the pages. Here is a tutorial on how to reinstall missing Woocommerce pages.

  1. After logging in to your WP admin
  2. Visit the Woocommerce > Status > Tools
  3. Choose “Create Pages” from the “Create default WooCommerce pages”. The pages will be produced as a result.
  4. By doing this, the pages will be correctly linked to one another.
  5. Verify that the Woocommerce pages are now visible.

You should be able to reinstall the missing Woocommerce pages by following the procedures above.

Shortcode of a Long Description for Woocommerce

Would you like to include a detailed and long description of your product in a custom accordion rather than using the default style of your WordPress theme? So, this article is for you.

Adding this code to your WooCommerce site is easy and will allow you to create a shortcode to display the product description for any product.

// Create a shortcode for product description of Woocommerce

add_shortcode( 'product_description', 'display_product_description' );
function display_product_description( $atts ){
$atts = shortcode_atts( array(
'id' => get_the_id(),
), $atts, 'product_description' );

global $product;

if ( ! is_a( $product, 'WC_Product') )
$product = wc_get_product($atts['id']);

return wpautop($product->get_description());
}

Here are the steps you should take to add the code:

  1. Log into your WordPress dashboard and navigate to the ‘Appearance’ section.
  2. Click on the ‘Editor’ option.
  3. In the right-hand pane, select the ‘functions.php’ file.
  4. Copy and paste the code snippet provided above into the file.
  5. Click on the ‘Update File’ button to save your changes.

Once you’ve saved the changes to the functions.php file, you will now be able to use the shortcode [product_description] wherever you need to display the product description. And, you’re also able to enter the product’s ID in the shortcode (e.g. ‘[product_description id=123]’) to get the exactly Product ID. In case you’re adding it directly to the product page, no need to add the product_id.

That’s it! You’ve now successfully added the code snippet to your WooCommerce site.

Ecommerce Admin Dashboard in WordPress

Learn how to customize your WordPress Admin Menu focused on your online store, you will have the left Menu like this:

  1. Woocommerce Settings
  2. Pages and Customization Settings
  3. Theme Settings
  4. Users Settings
  5. Visit Site

Before watching the video, please make sure you have the proper plugin and the Menu Template in hands, feel free to download it in the links below:

  • Click here to download menu Template in .txt file
  • Click here to install the Admin Menu Editor plugin

This is the function that you will use to get the Woocommerce Home Page as first page after logging in:

function loginRedirect( $redirect_to, $request, $user ){if( is_array( $user->roles ) ) { // check if user has a rolereturn "/wp-admin/admin.php?page=wc-admin";}}add_filter("login_redirect", "loginRedirect", 10, 3);

Paste this function in Appearance > Theme Editor > Theme Functions (inside functions.php file) – we recommend to watch the video.

Watch the video and build your own Woocommerce Admin menu, feel free to make your changes after watching the tutorial, it’s up to you:

Do you want to jump to a specific part of the video?

  • 00:13 – Plugin installation
  • 01:16 – Showing the Template Menu .txt file
  • 01:40 – Adding Woocommerce home page in the menu
  • 02:51 – Adding the Ecommerce settings in the menu
  • 08:16 – Adding the Pages and Appearance settings in the menu
  • 09:40 – Adding the Theme and Updates settings in the menu
  • 10:55 – Adding Users settings in the menu
  • 11:37 – Adding the Woocommerce settings in the menu
  • 12:12 – Adding Visit Site option in the menu
  • 12:45 – Hiding all useless menu options
  • 13:15 – Showing the final result
  • 13:39 – Finishing some dropdown options and checking if it’s all done
  • 16:31 – Setting up a new customized Home Page on your WP admin

If you need any further help, feel free to contact us at info@flatzone.cc

Done! Enjoy your new WordPress admin Menu and save time from you and focus in increasing your sales.

You cannot copy content of this page

To provide you with a better browsing experience, this website utilizes cookies. You consent to our usage of cookies if you browse this website.