redirect after purchase
Is there a redirect after purchase option? I'd like to redirect to Fluent Booking page after someone purchases a coaching session.
Currently, we do not have this feature built-in. You need to use a hook as a workaround. In the upcoming release, we will make it built-in.
Thanks for your query
Ripon SarkarΒ each product needs the option for a URL redirect. We can create a thank you page with instructions for the product they just purchased.
Ripon SarkarΒ yeah we def need individual product redirections.... so a person purchasing a communit can go to that or a person that ordered a DFY server can go to an onboarding form etc.
Thanks!
Sarkar RiponΒ so is it built it or not? its been 8 months.
I have tried both these in code snippet and I am still being sent to default /receipt page... any suggestions?
1st attempt: (obviously I replaced the url and product id with correct link and id
add_action('fluentcart_order_status_completed', function($orderId, $order) {
// get items as an array
$items = isset($order->items) ? $order->items : (isset($order['items']) ? $order['items'] : []);
$shouldRedirect = false;
// Loop through items to find a target product ID foreach ($items as $item) {if ((isset($item->product_id) && $item->product_id == 40411) || (isset($item['product_id']) && $item['product_id'] == 40411)) {$shouldRedirect = true; break; } } // Run redirect only if product found if ($shouldRedirect && defined('DOING_AJAX') && DOING_AJAX) { if (!headers_sent()) { wp_redirect('https://infinitemasteryconsulting.com/mmc_calls'); exit; } }
}, 10, 2);
2nd Attempt:
add_filter('fluentcart_checkout_redirect_url', function($url, $order) {
$items = isset($order->items) ? $order->items : (isset($order['items']) ? $order['items'] : []);
$target_product_id = 40411;
foreach ($items as $item) {
$pid = isset($item->product_id) ? $item->product_id : (isset($item['product_id']) ? $item['product_id'] : null);
if ($pid == $target_product_id) {
return 'https://infinitemasteryconsulting.com/mmc_calls';
}
}
return $url; // default receipt page for all other products
}, 10, 2);
Thanks.
Ripon SarkarΒ I was hoping this would have been added to this update but I did not see it listed nor do I see anything in Product edits that allow this action yet... please look at the code snippet I added and let me know if you can see any errors, or can suggest something that will work. Also if you have any insights as to when this feature will be a part of an update? Thanks in advance.
I figured it out for those who want to get this done. This method bypasses the receipt page and auto redirects the user to a specific landing page AFTER purchasing a specific product.... here's the code added to functions.php... REPLACE Product ID and Redirect URL with your own.
/**
- Immediate redirect on receipt page for specific product
*/
// Step 1: Store redirect when order is paid
add_action('fluent_cart/order_paid_done', function($data) {
$order = $data['order'];
$target_product_id = PRODUCTID;
$redirect_url = 'https://REDIRECTURL.COM';
if (!empty($order->order_items)) {
foreach ($order->order_items as $item) {
if ($item->post_id == $target_product_id) {
// Store redirect by order ID
set_transient('fluentcart_redirect_' . $order->id, $redirect_url, 3600);
error_log('FluentCart: Redirect stored for Order #' . $order->id);
break;
}
}
}
}, 10, 1);
// Step 2: Inject immediate JavaScript redirect on receipt page
add_action('fluent_cart/after_receipt', function($data) {
$order = $data['order'];
// Check for redirect
$redirect_url = get_transient('fluentcart_redirect_' . $order->id);
if ($redirect_url) {
// Clean up transient
delete_transient('fluentcart_redirect_' . $order->id);
error_log('FluentCart: Immediate JS redirect for Order #' . $order->id);
// Output JavaScript that runs IMMEDIATELY
?>
<script type="text/javascript">
(function() {
window.location.replace('<?php echo esc_url($redirect_url); ?>');
})();
</script>
<?php
// Also try to stop any further output
exit;
}
}, 1, 1); // Priority 1 to run as early as possible
Hi! Just checking if there are any updates on this or the implementation timeline? Thanks!