Filter
uncanny-automator-pro
automator_woocommerce_product_rating
Filters the WooCommerce product rating trigger result before it's processed by Automator.
add_filter( 'automator_woocommerce_product_rating', $callback, 10, 3 );
Description
Fires after a WooCommerce product rating is submitted. Developers can use this filter to modify the rating value before it's processed by Uncanny Automator. It receives the rating, the POST data, and the trigger result.
Usage
add_filter( 'automator_woocommerce_product_rating', 'your_function_name', 10, 3 );
Parameters
-
$_POST(mixed) - This parameter contains the POST data related to the product rating, which is a mixed data type.
-
$_POST(mixed) - This parameter likely contains data related to a product rating submission, potentially including the rating value itself or associated product information.
-
$trigger_result(mixed) - This parameter contains the rating value submitted by the user, likely from a form submission.
Return Value
The filtered value.
Examples
/**
* Example of how to hook into the 'automator_woocommerce_product_rating' filter.
* This example demonstrates how to modify the product rating before it's processed
* by Uncanny Automator, for instance, by adding a penalty or bonus based on certain conditions.
*
* @param int $rating The original product rating (an integer between 1 and 5).
* @param array $posted_data The entire $_POST array from the WooCommerce submission.
* @param mixed $trigger_result The result of the trigger execution.
*
* @return int The modified product rating.
*/
function my_automator_modify_product_rating( $rating, $posted_data, $trigger_result ) {
// Check if a specific product ID is present in the posted data.
// For example, let's say we want to slightly increase ratings for product ID 123.
$product_id = isset( $posted_data['product_id'] ) ? absint( $posted_data['product_id'] ) : 0;
// Define the product ID we want to apply a modification to.
$special_product_id = 123;
// Define the amount to adjust the rating by.
$rating_adjustment = 0;
if ( $product_id === $special_product_id ) {
// Award a small bonus rating for this specific product.
// Ensure the rating doesn't exceed the maximum (5).
$rating_adjustment = 1;
$rating = min( 5, $rating + $rating_adjustment );
// You could also add logging here for debugging purposes.
// error_log( "Uncanny Automator: Increased rating for product {$product_id} by {$rating_adjustment}." );
}
// You could also implement logic based on other $_POST variables or the $trigger_result.
// For example, if the user is a VIP customer (you'd need a way to determine this):
// if ( isset( $posted_data['user_is_vip'] ) && 'yes' === $posted_data['user_is_vip'] ) {
// $rating_adjustment = -1; // Apply a penalty for VIPs in this hypothetical scenario.
// $rating = max( 1, $rating + $rating_adjustment );
// }
// Return the potentially modified rating.
return $rating;
}
add_filter( 'automator_woocommerce_product_rating', 'my_automator_modify_product_rating', 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:2099
'run_number' => $run_number,
//get run number
'trigger_log_id' => $trigger_log_id,
);
Automator()->insert_trigger_meta( $args );
if ( automator_filter_has_var( 'rating', INPUT_POST ) ) {
$rating = apply_filters( 'automator_woocommerce_product_rating', absint( $_POST['rating'] ), $_POST, $trigger_result );
$args = array(
'user_id' => $user_id,
'trigger_id' => $trigger_id,
'meta_key' => 'rating',
'meta_value' => $rating,
'run_number' => $run_number,
//get run number