Filter
uncanny-automator
automator_upsell_order_use_current_logged_user
Filters whether to use the current logged-in user for an upsell order, defaulting to false.
add_filter( 'automator_upsell_order_use_current_logged_user', $callback, 10, 1 );
Description
This filter controls whether to use the currently logged-in user or the order's customer for upsell plugin triggers. Return `true` to prioritize the logged-in user. By default, it attempts to find the user associated with the order's email. Use this to customize user assignment for specific scenarios.
Usage
add_filter( 'automator_upsell_order_use_current_logged_user', 'your_function_name', 10, 1 );
Parameters
-
$order(mixed) - This parameter is a boolean value that determines whether to use the currently logged-in user for the order, defaulting to false.
Return Value
The filtered value.
Examples
add_filter( 'automator_upsell_order_use_current_logged_user', 'my_automator_force_logged_in_user_for_upsell', 10, 2 );
/**
* Example filter to always use the currently logged-in user for upsell orders,
* regardless of the order's customer email.
*
* This is useful if your upsell process should be tied to the user currently
* interacting with the site, not necessarily the original purchaser of a past order.
*
* @param bool $use_current_user_for_upsell Whether to use the current logged-in user.
* @param object $order The order object for which the upsell is being considered.
*
* @return bool True to force using the current logged-in user, false to use the order's customer.
*/
function my_automator_force_logged_in_user_for_upsell( $use_current_user_for_upsell, $order ) {
// Always return true to force the use of the current logged-in user.
// If you wanted to conditionally force it, you would add logic here.
// For instance: if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) { return true; }
return true;
}
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
src/integrations/upsell-plugin/triggers/upsell-plugin-purchprod.php:79
return;
}
if ( 'completed' !== $order->status() ) {
return;
}
if ( true === apply_filters( 'automator_upsell_order_use_current_logged_user', false, $order ) ) {
$user_id = get_current_user_id();
} else {
$customer = get_user_by( 'email', $order->customer_email );
$user_id = ( ! empty( $customer ) ) ? $customer->ID : 0;
}
if ( 0 === $user_id ) {