| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle frontend |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Frontend; |
| 8 |
|
| 9 |
|
| 10 |
use WPFunnels\Wpfnl_functions; |
| 11 |
|
| 12 |
class Wpfnl_Frontend |
| 13 |
{ |
| 14 |
public function __construct() |
| 15 |
{ |
| 16 |
add_filter('woocommerce_get_checkout_order_received_url', [ $this, 'redirect_to_next_step' ], 1000, 2); |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
/** |
| 21 |
* Next step url after checkout is |
| 22 |
* completed |
| 23 |
* |
| 24 |
* @param $order_received_url |
| 25 |
* @param $order |
| 26 |
* |
| 27 |
* @return string |
| 28 |
*/ |
| 29 |
public function redirect_to_next_step($order_received_url, $order) |
| 30 |
{ |
| 31 |
$order_key = $order->get_order_key(); |
| 32 |
$order_id = $order->get_id(); |
| 33 |
$current_page_id = get_post_meta($order_id, '_wpfunnel_checkout_id', true); |
| 34 |
$funnel_id = get_post_meta($order_id, '_wpfunnel_id', true); |
| 35 |
$next_step = Wpfnl_functions::get_next_step($funnel_id, $current_page_id); |
| 36 |
if ($next_step) { |
| 37 |
|
| 38 |
$custom_url = Wpfnl_functions::custom_url_for_thankyou_page( $next_step['id'] ); |
| 39 |
if( $custom_url ){ |
| 40 |
return $custom_url; |
| 41 |
} |
| 42 |
|
| 43 |
$next_step_link = get_page_link($next_step['id']); |
| 44 |
$permalink_structure = get_option('permalink_structure'); |
| 45 |
if ($permalink_structure) { |
| 46 |
$redirect_link = $next_step_link.'?order_id='.$order_id.'&order_key='.$order_key; |
| 47 |
} else { |
| 48 |
$redirect_link = $next_step_link.'&order_id='.$order_id.'&order_key='.$order_key; |
| 49 |
} |
| 50 |
|
| 51 |
return $redirect_link; |
| 52 |
} |
| 53 |
return $order_received_url; |
| 54 |
} |
| 55 |
} |
| 56 |
|