NextMove WooCommerce Thank You Page Compatibility With 1 Click Upsell plugin
<?php
/**
* Compatibility of NextMove plugin with 1-Click Upsells and Downsells plugin
* NextMove WooCommerce Thank You Page - https://xlplugins.com/woocommerce-thank-you-page-nextmove/
* 1-Click Upsells and Downsells - https://woocurve.com/one-click-upsells-for-woocommerce/
*
* Change order received URL
* If 1-Click Upsell plugin modified the URL then return same
* Else run NextMove campaigns
*/
add_action( 'plugins_loaded', function () {
if ( function_exists( 'XLWCTY_Core' ) ) {
// un-hook nextmove xlwcty 'redirect_to_thankyou' function
remove_filter( 'woocommerce_get_checkout_order_received_url', array( XLWCTY_Core()->public, 'redirect_to_thankyou' ), 99, 2 );
// hook on woocommerce_get_checkout_order_received_url to allow 1 click upsell plugin check
add_filter( 'woocommerce_get_checkout_order_received_url', 'xlwcty_cmp_1cu_checkout_order_received_url', 99, 2 );
}
}, 3 );
if ( ! function_exists( 'xlwcty_cmp_1cu_checkout_order_received_url' ) ) {
function xlwcty_cmp_1cu_checkout_order_received_url( $link, $order ) {
$parse_link = wp_parse_url( $link );
// checking if upsell plugin has modified the thank you url of order
if ( isset( $parse_link['query'] ) && strpos( $parse_link['query'], '1cu' ) !== false ) {
return $link;
}
// continue carry on with nextmove's functionality
$default_settings = XLWCTY_Core()->data->get_option();
if ( isset( $default_settings['xlwcty_preview_mode'] ) && $default_settings['xlwcty_preview_mode'] == 'sandbox' ) {
return $link;
}
$get_link = XLWCTY_Core()->data->setup_thankyou_post( XLWCTY_Compatibility::get_order_id( $order ), XLWCTY_Core()->public->is_preview )->get_page_link();
if ( $get_link !== false ) {
return ( XLWCTY_Core()->public->prepare_single_post_url( $get_link, $order ) );
}
return $link;
}
}