• Resolved M Usman

    (@hafizusman)


    I have plugin which is getting average rating

    get_post_meta( $product_id, '_wc_average_rating', true );
    but after installing WooCommerce Multilingual it is displaying wrong value, when i deactivate WooCommerce Multilingual then its again showing correct value.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello!
    Could you provide more information about the problem, please?
    How is possible for me to test this and reproduce it?

    Perhaps you should check if the value is not obtained somehow from the original product – instead of the translated product.
    Maybe if you use https://wpml.org/wpml-hook/wpml_object_id/ to hook the ID to the language that you wish to display the value from – it might be this the key to solving the problem?

    Thread Starter M Usman

    (@hafizusman)

    Hi I have check you are using filter hook for _wc_average_rating

    const WCML_AVERAGE_RATING_KEY = '_wcml_average_rating';
    
    public function filter_average_rating( $value, $object_id, $meta_key, $single ) {
    
    		$filtered_value = $value;
    
    		if ( in_array( $meta_key, array( '_wc_average_rating', self::WC_REVIEW_COUNT_KEY ) ) && 'product' === get_post_type( $object_id ) ) {
    
    			switch ( $meta_key ){
    				case '_wc_average_rating':
    					$filtered_value = get_post_meta( $object_id, self::WCML_AVERAGE_RATING_KEY, $single );
    					break;
    				case self::WC_REVIEW_COUNT_KEY:
    					if ( $this->is_reviews_in_all_languages( $object_id ) ) {
    						$filtered_value = get_post_meta( $object_id, self::WCML_REVIEW_COUNT_KEY, $single );
    					}
    					break;
    			}
    		}
    
    		return !empty( $filtered_value ) ? $filtered_value : $value;
    	}

    That are not returning the actual result. I don’t know who you are storing the result in post_meta _wcml_average_rating, but in my case it is not returning the actual result.

    Hello again.

    You said that the code is not returning you a result.
    Could you elaborate a bit more, please?

    Currently, I am unable to reproduce issue like the one that you have reported, so it would be very nice if you can provide steps on how to reproduce that problem with the average_rating or perhaps create a ticket in our forum at wpml.org so that we can debug this more closely on your environment.

    Plugin Contributor Andreas Panag

    (@andrewp-2)

    Since we don’t have news for some time, I am closing this ticket.

    If you still have problem, please feel free to open a ticket in wpml.org so we can help you.

    Thank you very much

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘bug related to _wc_average_rating’ is closed to new replies.