Below, you’ll find a detailed guide on how to add the Customer Reviews for WooCommerce Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Customer Reviews for WooCommerce Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Customer Reviews for WooCommerce Plugin and the shortcodes it provides:
"Customer Reviews for WooCommerce is a versatile plugin that enhances your online store by collecting and showcasing customer feedback, thereby boosting credibility and sales."
- [cusrev_all_reviews]
- [cusrev_reviews_grid]
- [cusrev_reviews_slider]
- [cusrev_qna]
- [cusrev_trustbadge]
- [cusrev_reviews]
Customer Reviews for WooCommerce [cusrev_all_reviews] Shortcode
The ‘cusrev_all_reviews’ shortcode from the Customer Reviews WooCommerce plugin is designed to display all customer reviews. This shortcode is flexible and can be used with or without parameters. The associated PHP function, ‘render_all_reviews_shortcode’, processes the attributes of the shortcode. If no parameters are provided, it initializes an empty array. It then calls ‘fill_attributes’ to populate the array and ‘display_reviews’ to render the reviews.
Shortcode: [cusrev_all_reviews]
Examples and Usage
Basic example – The following shortcode displays all the customer reviews without any specific parameters.
[cusrev_all_reviews]
PHP Function Code
In case you have difficulties debugging what causing issues with [cusrev_all_reviews]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'cusrev_all_reviews', array( $this, 'render_all_reviews_shortcode' ) );
Shortcode PHP function:
function render_all_reviews_shortcode( $attributes ) {
if ( ! is_array( $attributes ) ) {
// if the shortcode is used without parameters, $attributes will be an empty string
$attributes = array();
}
$this->fill_attributes( $attributes );
return $this->display_reviews();
}
Code file location:
customer-reviews-woocommerce/customer-reviews-woocommerce/includes/blocks/class-cr-all-reviews.php
Customer Reviews for WooCommerce [cusrev_reviews_grid] Shortcode
The ‘cusrev_reviews_grid’ shortcode from the Customer Reviews WooCommerce plugin creates a grid layout for product reviews. It allows customization of review count, product links, sorting options, and more. .
Shortcode: [cusrev_reviews_grid]
Parameters
Here is a list of all possible cusrev_reviews_grid shortcode parameters and attributes:
count
– Defines the number of reviews to display.show_products
– Controls whether product names are shown in reviews.product_links
– Toggles the activation of links in product names.sort_by
– Sets the sorting parameter for reviews (by date, rating, etc).sort
– Determines the sort order (ascending or descending).categories
– Filters reviews by specific product categories.products
– Filters reviews by specific products.color_ex_brdr
– Sets the color of the external border.color_brdr
– Sets the color of the border.color_ex_bcrd
– Sets the color of the external card background.color_bcrd
– Sets the color of the card background.color_pr_bcrd
– Sets the color of the product card background.color_stars
– Sets the color of the review stars.shop_reviews
– Controls whether to display shop reviews.count_shop_reviews
– Defines the number of shop reviews to display.inactive_products
– Controls whether to show reviews of inactive products.avatars
– Determines the type of avatars displayed.show_more
– Controls whether to display a “show more” button.count_total
– Defines the total number of reviews to display.product_tags
– Filters reviews by specific product tags.min_chars
– Sets the minimum character limit for reviews.show_summary_bar
– Controls whether to display a summary bar with ratings.comment__not_in
– Excludes specific comments from the review grid.
Examples and Usage
Basic example – Displaying a reviews grid with default settings
[cusrev_reviews_grid]
Advanced examples
Displaying a reviews grid with a specific count of reviews and showing product links
[cusrev_reviews_grid count=5 product_links=true]
Displaying a reviews grid with reviews sorted by date in ascending order
[cusrev_reviews_grid sort_by=date sort=ASC]
Displaying a reviews grid with reviews from specific categories and excluding inactive products
[cusrev_reviews_grid categories="category1, category2" inactive_products=false]
Displaying a reviews grid with reviews of a specific product
[cusrev_reviews_grid products=123]
Displaying a reviews grid with a specific color scheme and showing the summary bar
[cusrev_reviews_grid color_brdr="#000000" color_bcrd="#ffffff" color_stars="#ff0000" show_summary_bar=true]
Displaying a reviews grid with reviews that have a minimum character count
[cusrev_reviews_grid min_chars=50]
Displaying a reviews grid with reviews tagged with specific product tags
[cusrev_reviews_grid product_tags="tag1, tag2"]
PHP Function Code
In case you have difficulties debugging what causing issues with [cusrev_reviews_grid]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'cusrev_reviews_grid', array( $this, 'render_reviews_grid_shortcode' ) );
Shortcode PHP function:
function render_reviews_grid_shortcode( $attributes ) {
$shortcode_enabled = get_option( 'ivole_reviews_shortcode', 'no' );
if( $shortcode_enabled === 'no' ) {
return;
} else {
// Convert shortcode attributes to block attributes
$attributes = shortcode_atts( array(
'count' => 3,
'show_products' => true,
'product_links' => true,
'sort_by' => 'date',
'sort' => 'DESC',
'categories' => array(),
'products' => 'current',
'color_ex_brdr' => '#ebebeb',
'color_brdr' => '#ebebeb',
'color_ex_bcrd' => '',
'color_bcrd' => '#ffffff',
'color_pr_bcrd' => '#f4f4f4',
'color_stars' => '#FFD707',
'shop_reviews' => 'false',
'count_shop_reviews' => 1,
'inactive_products' => 'false',
'avatars' => 'initials',
'show_more' => 0,
'count_total' => 0,
'product_tags' => [],
'min_chars' => 0,
'show_summary_bar' => 'false',
'comment__not_in' => []
), $attributes, 'cusrev_reviews_grid' );
$attributes['count'] = absint( $attributes['count'] );
$attributes['show_products'] = ( $attributes['show_products'] !== 'false' && boolval( $attributes['count'] ) );
$attributes['product_links'] = ( $attributes['product_links'] !== 'false' );
$attributes['shop_reviews'] = ( $attributes['shop_reviews'] !== 'false' && boolval( $attributes['count_shop_reviews'] ) );
$attributes['count_shop_reviews'] = absint( $attributes['count_shop_reviews'] );
$attributes['inactive_products'] = ( $attributes['inactive_products'] === 'true' );
$attributes['show_more'] = absint( $attributes['show_more'] );
$attributes['count_total'] = absint( $attributes['count_total'] );
$attributes['min_chars'] = intval( $attributes['min_chars'] );
$attributes['show_summary_bar'] = ( $attributes['show_summary_bar'] === 'true' );
if( $attributes['min_chars'] < 0 ) {
$attributes['min_chars'] = 0;
}
if ( ! is_array( $attributes['categories'] ) ) {
$attributes['categories'] = array_filter( array_map( 'trim', explode( ',', $attributes['categories'] ) ) );
}
if (
is_string( $attributes['products'] ) &&
'current' === trim( strtolower( $attributes['products'] ) )
) {
if ( is_product() ) {
$product = wc_get_product();
if ( is_object( $product ) ) {
$id = $product->get_id();
$attributes['products'] = array( $id );
} else {
$attributes['products'] = array();
}
} else {
$attributes['products'] = array();
}
} elseif ( ! is_array( $attributes['products'] ) ) {
$products = str_replace( ' ', '', $attributes['products'] );
$products = explode( ',', $products );
$products = array_filter( $products, 'is_numeric' );
$products = array_map( 'intval', $products );
$attributes['products'] = $products;
} else {
$attributes['products'] = array_map( 'intval', $attributes['products'] );
}
if(
! empty( $attributes['product_tags'] ) &&
! is_array( $attributes['product_tags'] )
) {
$attributes['product_tags'] = array_filter( array_map( 'trim', explode( ',', $attributes['product_tags'] ) ) );
}
return $this->render_reviews_grid( $attributes );
}
}
Code file location:
customer-reviews-woocommerce/customer-reviews-woocommerce/includes/blocks/class-cr-reviews-grid.php
Customer Reviews for WooCommerce [cusrev_reviews_slider] Shortcode
The ‘cusrev_reviews_slider’ shortcode from the Customer Reviews WooCommerce plugin displays a slider of customer reviews. The shortcode offers customization options like the number of slides to show, review count, product links, and sorting options.
Shortcode: [cusrev_reviews_slider]
Parameters
Here is a list of all possible cusrev_reviews_slider shortcode parameters and attributes:
slides_to_show
– the number of reviews to display at once.count
– total number of reviews to show in the slider.show_products
– a flag to show or hide the product names in reviews.product_links
– a flag to enable or disable the links to the reviewed products.sort_by
– the attribute to sort the reviews by (e.g., date).sort
– the order to sort the reviews (e.g., DESC for descending).categories
– the specific product categories to show reviews for.products
– the specific products to show reviews for.color_ex_brdr
– the color of the external border of the review box.color_brdr
– the color of the internal border of the review box.color_ex_bcrd
– the external background color of the review box.color_bcrd
– the internal background color of the review box.color_pr_bcrd
– the background color of the product box in the review.color_stars
– the color of the review stars.shop_reviews
– a flag to show or hide shop reviews.count_shop_reviews
– the number of shop reviews to show.inactive_products
– a flag to include reviews for inactive products.autoplay
– a flag to enable or disable automatic sliding of reviews.avatars
– the type of avatars to show for reviewers.max_chars
– the maximum number of characters for review content.product_tags
– specific product tags to show reviews for.min_chars
– the minimum number of characters for review content.show_dots
– a flag to show or hide navigation dots.
Examples and Usage
Basic Example – Display a simple review slider with default settings.
[cusrev_reviews_slider]
Advanced examples:
Display a review slider with 5 slides to show, 10 total reviews, sorted by date in descending order, and with product links enabled.
[cusrev_reviews_slider slides_to_show=5 count=10 sort_by="date" sort="DESC" product_links=true]
Display a review slider with specific product and category, with inactive products included, and autoplay enabled.
[cusrev_reviews_slider products="10,20,30" categories="1,2,3" inactive_products=true autoplay=true]
Display a review slider with a minimum character count of 50 for reviews, maximum character count of 500, and dots for navigation enabled.
[cusrev_reviews_slider min_chars=50 max_chars=500 show_dots=true]
PHP Function Code
In case you have difficulties debugging what causing issues with [cusrev_reviews_slider]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'cusrev_reviews_slider', array( $this, 'render_reviews_slider_shortcode' ) );
Shortcode PHP function:
function render_reviews_slider_shortcode( $attributes ) {
$shortcode_enabled = get_option( 'ivole_reviews_shortcode', 'no' );
if( $shortcode_enabled === 'no' ) {
return;
} else {
// Convert shortcode attributes
$attributes = shortcode_atts( array(
'slides_to_show' => 3,
'count' => 5,
'show_products' => true,
'product_links' => true,
'sort_by' => 'date',
'sort' => 'DESC',
'categories' => array(),
'products' => 'current',
'color_ex_brdr' => '#ebebeb',
'color_brdr' => '#ebebeb',
'color_ex_bcrd' => '',
'color_bcrd' => '#fbfbfb',
'color_pr_bcrd' => '#f2f2f2',
'color_stars' => '#6bba70',
'shop_reviews' => 'false',
'count_shop_reviews' => 1,
'inactive_products' => false,
'autoplay' => false,
'avatars' => 'initials',
'max_chars' => 0,
'product_tags' => array(),
'min_chars' => 0,
'show_dots' => true,
), $attributes, 'cusrev_reviews_slider' );
$attributes['slides_to_shows'] = absint( $attributes['slides_to_show'] ) >= absint( $attributes['count'] ) ? absint( $attributes['count'] ) : absint( $attributes['slides_to_show'] );
$attributes['count'] = absint( $attributes['count'] );
$attributes['show_products'] = ( $attributes['show_products'] !== 'false' && boolval( $attributes['count'] ) );
$attributes['product_links'] = ( $attributes['product_links'] !== 'false' );
$attributes['shop_reviews'] = ( $attributes['shop_reviews'] !== 'false' && boolval( $attributes['count_shop_reviews'] ) );
$attributes['count_shop_reviews'] = absint( $attributes['count_shop_reviews'] );
$attributes['inactive_products'] = ( $attributes['inactive_products'] === 'true' );
$attributes['autoplay'] = ( $attributes['autoplay'] === 'true' );
$attributes['max_chars'] = absint( $attributes['max_chars'] );
$attributes['min_chars'] = intval( $attributes['min_chars'] );
$attributes['show_dots'] = ( $attributes['show_dots'] !== 'false' );
if( $attributes['min_chars'] < 0 ) {
$attributes['min_chars'] = 0;
}
if ( ! is_array( $attributes['categories'] ) ) {
$attributes['categories'] = array_filter( array_map( 'trim', explode( ',', $attributes['categories'] ) ) );
}
if (
is_string( $attributes['products'] ) &&
'current' === trim( strtolower( $attributes['products'] ) )
) {
if ( is_product() ) {
$product = wc_get_product();
if ( is_object( $product ) ) {
$id = $product->get_id();
$attributes['products'] = array( $id );
} else {
$attributes['products'] = array();
}
} else {
$attributes['products'] = array();
}
} elseif ( ! is_array( $attributes['products'] ) ) {
$products = str_replace( ' ', '', $attributes['products'] );
$products = explode( ',', $products );
$products = array_filter( $products, 'is_numeric' );
$products = array_map( 'intval', $products );
$attributes['products'] = $products;
} else {
$attributes['products'] = array();
}
if( $attributes['slides_to_shows'] <= 0 ) {
$attributes['slides_to_shows'] = 1;
}
if( ! empty( $attributes['product_tags'] ) ) {
$attributes['product_tags'] = array_filter( array_map( 'trim', explode( ',', $attributes['product_tags'] ) ) );
}
return $this->render_reviews_slider( $attributes );
}
}
Code file location:
customer-reviews-woocommerce/customer-reviews-woocommerce/includes/blocks/class-cr-reviews-slider.php
Customer Reviews for WooCommerce [cusrev_qna] Shortcode
The ‘cusrev_qna’ shortcode from the Customer Reviews WooCommerce plugin allows for the display of product-specific Q&A sections. It checks if Q&A is enabled, then retrieves product and shop attributes. The function ‘render_cusrev_qna_shortcode’ processes these attributes. If they are not arrays, it trims the values. If the attributes are not empty and not set to ‘all’, it trims and explodes them by commas. Finally, it starts an output buffer, displays the Q&A tab, and returns the output.
Shortcode: [cusrev_qna]
Parameters
Here is a list of all possible cusrev_qna shortcode parameters and attributes:
products
– Specifies the products to display Q & A for.shop
– Defines the shops for which Q & A should be displayed.
Examples and Usage
Basic example – Display the Q&A section for all products in the store.
[cusrev_qna products="all" /]
Advanced examples
Display the Q&A section for specific products by referencing their IDs.
[cusrev_qna products="101,102,103" /]
Display the Q&A section for specific shops by referencing their IDs.
[cusrev_qna shop="201,202,203" /]
Display the Q&A section for specific products in specific shops by referencing their IDs.
[cusrev_qna products="101,102,103" shop="201,202,203" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [cusrev_qna]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'cusrev_qna', array( $this, 'render_cusrev_qna_shortcode' ) );
Shortcode PHP function:
function render_cusrev_qna_shortcode( $attributes ) {
if( 'yes' !== get_option( 'ivole_questions_answers', 'no' ) ) {
echo 'Q & A are disabled in the settings';
return;
}
$attributes = shortcode_atts( array(
'products' => [],
'shop' => [],
), $attributes, 'cusrev_qna' );
if( !is_array( $attributes['products'] ) ) {
$attributes['products'] = trim( $attributes['products'] );
}
if( !empty( $attributes['products'] ) && $attributes['products'] !== 'all' ) {
$attributes['products'] = array_map( 'trim', explode( ',', $attributes['products'] ) );
}
if( !is_array($attributes['shop']) ) {
$attributes['shop'] = trim( $attributes['shop'] );
}
if( !empty( $attributes['shop'] ) && $attributes['shop'] !== 'all'){
$attributes['shop'] = array_map( 'trim', explode( ',', $attributes['shop'] ) );
}
ob_start();
$this->qna->display_qna_tab( $attributes );
$output = ob_get_clean();
return $output;
}
Code file location:
customer-reviews-woocommerce/customer-reviews-woocommerce/includes/qna/class-cr-qna-shortcode.php
Customer Reviews for WooCommerce [cusrev_trustbadge] Shortcode
The Customer Reviews WooCommerce plugin shortcode is designed to render a trust badge on your website. It uses the ‘cusrev_trustbadge’ shortcode to enable this feature. The shortcode accepts three parameters: ‘type’, ‘border’, and ‘color’. It validates these attributes, ensuring the ‘type’ and ‘border’ values are allowed and the ‘color’ is a valid hex color code. After validation, it merges the attributes with the default values and displays the trust badge. This enhances the credibility of your WooCommerce store by showcasing customer reviews.
Shortcode: [cusrev_trustbadge]
Parameters
Here is a list of all possible cusrev_trustbadge shortcode parameters and attributes:
type
– defines the style of the trust badgeborder
– determines if the badge has a border or notcolor
– sets the color of the trust badge
Examples and Usage
Basic example – A basic usage of the ‘cusrev_trustbadge’ shortcode with default parameters.
[cusrev_trustbadge /]
Advanced examples
Here, we’re using the ‘cusrev_trustbadge’ shortcode to display a trust badge of type ‘slp’ (small light with product rating) and with a border.
[cusrev_trustbadge type="slp" border="yes" /]
In this example, we’re using the ‘cusrev_trustbadge’ shortcode to display a trust badge of type ‘wd’ (wide dark) without a border, and with a custom color.
[cusrev_trustbadge type="wd" border="no" color="#ff0000" /]
In the following example, the ‘cusrev_trustbadge’ shortcode is used to display a trust badge of type ‘vsl’ (vertical small light) with a border and a custom color. If the given color is not valid, the color attribute will be ignored.
[cusrev_trustbadge type="vsl" border="yes" color="#123abc" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [cusrev_trustbadge]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'cusrev_trustbadge', array( $this, 'render_trustbadge_shortcode' ) );
Shortcode PHP function:
function render_trustbadge_shortcode( $attributes ) {
wp_enqueue_style( 'cr-badges-css' );
$defaults = array(
'type' => 'sl',
'border' => 'yes',
'color' => ''
);
if ( isset( $attributes['type'] ) ) {
$type = str_replace( ' ', '', $attributes['type'] );
$type = strtolower( $type );
$allowed_types = array( 'sl', 'slp', 'sd', 'sdp', 'wl', 'wlp', 'wd', 'wdp', 'vsl', 'vsd' );
if( in_array( $type, $allowed_types ) ) {
$attributes['type'] = $type;
} else {
$attributes['type'] = null;
}
}
if ( isset( $attributes['border'] ) ) {
$border = str_replace( ' ', '', $attributes['border'] );
$border = strtolower( $border );
$allowed_borders = array( 'yes', 'no' );
if( in_array( $border, $allowed_borders ) ) {
$attributes['border'] = $border;
} else {
$attributes['border'] = 'yes';
}
}
if ( isset( $attributes['color'] ) ) {
$color = str_replace( ' ', '', $attributes['color'] );
$color = strtolower( $color );
if( preg_match( '/#([a-f0-9]{3}){1,2}\b/i', $color ) ) {
$attributes['color'] = $color;
} else {
$attributes['color'] = '';
}
}
$this->shortcode_atts = shortcode_atts( $defaults, $attributes );
return $this->show_trust_badge();
}
Code file location:
customer-reviews-woocommerce/customer-reviews-woocommerce/includes/trust-badge/class-cr-trust-badge.php
Customer Reviews for WooCommerce [cusrev_reviews] Shortcode
The ‘cusrev_reviews’ shortcode is part of the Customer Reviews WooCommerce plugin. It enables the display of customer reviews on your website. The PHP function ‘ivole_reviews_shortcode’ checks if the shortcode is enabled. If it is, it extracts attributes and returns a comment form. The ‘comment_file’ attribute can be customized to your preference.
Shortcode: [cusrev_reviews]
Parameters
Here is a list of all possible cusrev_reviews shortcode parameters and attributes:
comment_file
– specifies the location of the comment form file
Examples and Usage
Basic example – A simple usage of the ‘cusrev_reviews’ shortcode without any parameters. It will call the function ‘ivole_reviews_shortcode’ which in turn will display the comment form based on the default comment file.
[cusrev_reviews /]
Advanced examples
Displaying the comment form using a different comment file. Here, we are passing the ‘comment_file’ attribute to specify a different file for the comment form.
[cusrev_reviews comment_file='/my-comments.php' /]
Using multiple parameters in the shortcode. This example shows how to use more than one parameter. It will first try to load the comment form from ‘my-comments.php’, if not found, it will try to load from ‘another-comments.php’.
[cusrev_reviews comment_file='/my-comments.php' another_comment_file='/another-comments.php' /]
Please note that the actual functionality of these examples depends on how the ‘ivole_reviews_shortcode’ function is implemented and the valid parameters it accepts.
PHP Function Code
In case you have difficulties debugging what causing issues with [cusrev_reviews]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'cusrev_reviews', 'ivole_reviews_shortcode' );
Shortcode PHP function:
function ivole_reviews_shortcode( $atts, $content )
{
$shortcode_enabled = get_option( 'ivole_reviews_shortcode', 'no' );
if( $shortcode_enabled === 'no' ) {
return;
} else {
extract( shortcode_atts( array( 'comment_file' => '/comments.php' ), $atts ) );
$content = ivole_return_comment_form( $comment_file );
}
return $content;
}
Code file location:
customer-reviews-woocommerce/customer-reviews-woocommerce/ivole.php
Conclusion
Now that you’ve learned how to embed the Customer Reviews for WooCommerce Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply