: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* WooCommerce Modules: ET_Builder_Module_Woocommerce_Rating class
* The ET_Builder_Module_Woocommerce_Rating Class is responsible for rendering the
* Rating markup using the WooCommerce template.
* Class representing WooCommerce Rating component.
class ET_Builder_Module_Woocommerce_Rating extends ET_Builder_Module {
* @since 3.29.2 Added custom margin default.
$this->name = esc_html__( 'Woo Rating', 'et_builder' );
$this->plural = esc_html__( 'Woo Ratings', 'et_builder' );
$this->slug = 'et_pb_wc_rating';
$this->vb_support = 'on';
$this->settings_modal_toggles = array(
'main_content' => et_builder_i18n( 'Content' ),
'elements' => et_builder_i18n( 'Elements' ),
'layout' => et_builder_i18n( 'Layout' ),
// Avoid Text suffix by manually defining the `text` toggle slug.
'title' => et_builder_i18n( 'Text' ),
// Avoid Text suffix by manually defining the `star` toggle slug.
'star' => esc_html__( 'Star Rating', 'et_builder' ),
$this->advanced_fields = array(
'label' => esc_html__( 'Star Rating', 'et_builder' ),
'main' => '%%order_class%% .woocommerce-product-rating .star-rating',
'color' => '%%order_class%% .woocommerce-product-rating .star-rating > span:before',
'text_align' => '%%order_class%% .woocommerce-product-rating',
'hide_line_height' => true,
'hide_text_shadow' => true,
'label' => esc_html__( 'Star Rating Alignment', 'et_builder' ),
'label' => esc_html__( 'Star Rating Size', 'et_builder' ),
'label' => esc_html__( 'Star Rating Color', 'et_builder' ),
'label' => et_builder_i18n( 'Text' ),
'main' => '%%order_class%% a.woocommerce-review-link',
'hide_text_align' => true,
* Manually assign `text` toggle to avoid `Text Text` toggle defined by advanced
* field font which automatically append ` Text` by default.
'margin_padding' => array(
'custom_margin' => array(
'default' => '0em|0em|1.618em|0em|false|false',
// Don't add text-shadow fields since they already are via font-options.
$this->custom_css_fields = array(
'label' => et_builder_i18n( 'Text' ),
'selector' => 'a.woocommerce-review-link',
'star_rating_text' => array(
'label' => esc_html__( 'Star Rating', 'et_builder' ),
'selector' => '.woocommerce-product-rating .star-rating',
$this->help_videos = array(
'name' => esc_html__( 'Divi WooCommerce Modules', 'et_builder' ),
public function get_fields() {
'product' => ET_Builder_Module_Helper_Woocommerce_Modules::get_field(
'default' => ET_Builder_Module_Helper_Woocommerce_Modules::get_product_default(),
'computed_affects' => array(
'product_filter' => ET_Builder_Module_Helper_Woocommerce_Modules::get_field(
'computed_affects' => array(
'label' => esc_html__( 'Show Star Rating', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'configuration',
'on' => et_builder_i18n( 'On' ),
'off' => et_builder_i18n( 'Off' ),
'default_on_front' => 'on',
'toggle_slug' => 'elements',
'description' => esc_html__( 'Here you can choose whether the star rating should be added.', 'et_builder' ),
'mobile_options' => true,
'show_reviews_link' => array(
'label' => esc_html__( 'Show Customer Reviews Count', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'configuration',
'on' => et_builder_i18n( 'On' ),
'off' => et_builder_i18n( 'Off' ),
'default_on_front' => 'on',
'toggle_slug' => 'elements',
'description' => esc_html__( 'Here you can choose whether the custom reviews link should be added.', 'et_builder' ),
'mobile_options' => true,
'label' => esc_html__( 'Rating Layout', 'et_builder' ),
'option_category' => 'layout',
'inline' => esc_html__( 'Inline', 'et_builder' ),
'stacked' => esc_html__( 'Stacked', 'et_builder' ),
'tab_slug' => 'advanced',
'toggle_slug' => 'layout',
'description' => esc_html__( 'Here you can choose where to place the reviews link.', 'et_builder' ),
'default_on_front' => 'inline',
'computed_callback' => array(
'ET_Builder_Module_Woocommerce_Rating',
'computed_depends_on' => array(
'computed_minimum' => array(
public function get_transition_fields_css_props() {
$fields = parent::get_transition_fields_css_props();
$fields['rating_letter_spacing'] = array(
'width' => '%%order_class%% .star-rating',
'letter-spacing' => '%%order_class%% .star-rating',
* @param array $args Additional arguments.
public static function get_rating( $args = array() ) {
$args = wp_parse_args( $args, $defaults );
if ( 'current' !== $args['product'] ) {
// Enable comments via filter to render the reviews link.
add_filter( 'comments_open', '__return_true' );
$rating = et_builder_wc_render_module_template(
'woocommerce_template_single_rating',
array( 'product', 'wp_query' )
if ( 'current' !== $args['product'] ) {
// Remove filter after module is rendered.
remove_filter( 'comments_open', '__return_true' );
* Adds Multi view attributes to the Outer wrapper.
* Since we do not have control over the WooCommerce Rating markup, we inject Multi view
* attributes on to the Outer wrapper.
* @param array $outer_wrapper_attrs
public function add_multi_view_attrs( $outer_wrapper_attrs ) {
$multi_view = et_pb_multi_view_options( $this );
$multi_view_attrs = $multi_view->render_attrs( array(
'et_pb_wc_rating_no_rating' => array(
'et_pb_wc_rating_no_reviews' => array(
'show_reviews_link' => 'off',
if ( $multi_view_attrs && is_array( $multi_view_attrs ) ) {
$outer_wrapper_attrs = array_merge( $outer_wrapper_attrs, $multi_view_attrs );
return $outer_wrapper_attrs;
* Renders the module output.
* @param array $attrs List of attributes.
* @param string $content Content being processed.
* @param string $render_slug Slug of module that is used for rendering output.
public function render( $attrs, $content = null, $render_slug ) {
ET_Builder_Module_Helper_Woocommerce_Modules::process_background_layout_data( $render_slug, $this );
ET_Builder_Module_Helper_Woocommerce_Modules::add_star_rating_style(
'%%order_class%% .star-rating',
'%%order_class%%:hover .star-rating',
array( 'rating_letter_spacing' )
$this->add_classname( $this->get_text_orientation_classname() );
// Add classes to hide disabled elements.
if ( 'on' !== $this->props['show_rating'] ) {
$this->add_classname( 'et_pb_wc_rating_no_rating' );
if ( 'on' !== $this->props['show_reviews_link'] ) {
$this->add_classname( 'et_pb_wc_rating_no_reviews' );
if ( ! empty( $this->props['layout'] ) ) {
$this->add_classname( "et_pb_wc_rating_layout_{$this->props['layout']}" );
add_filter( "et_builder_module_{$render_slug}_outer_wrapper_attrs", array(
$output = self::get_rating( $this->props );
// Render empty string if no output is generated to avoid unwanted vertical space.
return $this->_render_module_wrapper( $output, $render_slug );
new ET_Builder_Module_Woocommerce_Rating();