Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save xlplugins/cc5ce85d11006ea059adb498dab8b9ca to your computer and use it in GitHub Desktop.

Select an option

Save xlplugins/cc5ce85d11006ea059adb498dab8b9ca to your computer and use it in GitHub Desktop.
Native checkout shows funnel upsell but must create checkout step in Funnel Builder
class WFACP_Do_Not_Override_Global_Checkout {
private $aero_id = 0;
public function __construct() {
add_action( 'wfacp_changed_default_woocommerce_page', [ $this, 'actions' ] );
add_filter( 'wfacp_template_class', [ $this, 'do_not_execute_aero_checkout' ] );
add_action( 'woocommerce_checkout_update_order_review', [ $this, 'woocommerce_checkout_update_order_review' ], - 5 );
}
public function actions( $aero_post_id ) {
remove_all_actions( 'wfacp_checkout_page_found' );
if ( $aero_post_id > 0 ) {
$this->aero_id = $aero_post_id;
$get_funnel_id = get_post_meta( $aero_post_id, '_bwf_in_funnel', true );
$get_funnel = new WFFN_Funnel( $get_funnel_id );
if ( ! wffn_is_valid_funnel( $get_funnel ) ) {
return;
}
WFFN_Core()->data->set( 'funnel', $get_funnel );
WFFN_Core()->data->set( 'current_step', [
'id' => $aero_post_id,
'type' => 'wc_checkout',
] );
WFFN_Core()->data->save();
add_action( 'woocommerce_checkout_after_order_review', [ $this, 'add_hidden_field' ] );
}
add_filter( 'wfacp_template_class', '__return_false' );
}
public function add_hidden_field() {
echo "<input type='hidden' name='_wfacp_post_id' value='$this->aero_id'>";
echo "<input type='hidden' name='_wfacp_convert_to_native' value='$this->aero_id'>";
}
public function do_not_execute_aero_checkout( $file ) {
if ( wp_doing_ajax() && false !== strpos( $_POST['post_data'], '_wfacp_convert_to_native' ) ) {
$file = false;
}
return $file;
}
public function woocommerce_checkout_update_order_review($posted_data){
$post_data = [];
parse_str( $posted_data, $post_data );
if ( isset( $post_data['_wfacp_post_id'] ) && $post_data['_wfacp_post_id'] == $this->aero_id ) {
remove_action( 'woocommerce_checkout_update_order_review', [ 'WFACP_Common', 'woocommerce_checkout_update_order_review' ], - 1 );
}
}
}
new WFACP_Do_Not_Override_Global_Checkout();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment