Last active
July 7, 2026 09:01
-
-
Save xlplugins/399f1f207b684d97745e4dee0aa06d61 to your computer and use it in GitHub Desktop.
Store Checkout — import legacy upsell offers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action( 'admin_init', function () { | |
| $run_key = 'fk_move_standalone_upsells_20260707c'; // change to re-run | |
| $log = function ( $m ) { if ( function_exists( 'wc_get_logger' ) ) { wc_get_logger()->info( $m, array( 'source' => 'fk-store-checkout-upsells' ) ); } }; | |
| if ( get_option( $run_key ) | |
| || ! class_exists( 'WFFN_Common' ) || ! class_exists( 'WFOCU_Common' ) || ! class_exists( 'WFFN_Funnel' ) ) { | |
| return; | |
| } | |
| $sc = absint( WFFN_Common::get_store_checkout_id() ); | |
| if ( $sc <= 0 ) { | |
| return; | |
| } | |
| $funnel_pt = WFOCU_Common::get_funnel_post_type_slug(); // wfocu_funnel | |
| $funnel = new WFFN_Funnel( $sc ); | |
| $steps = (array) $funnel->get_steps(); | |
| $step_ids = array_map( 'absint', wp_list_pluck( $steps, 'id' ) ); | |
| $log( 'MOVE START. sc=' . $sc . ' | BEFORE steps=' . wp_json_encode( $steps ) ); | |
| $anchor = 0; | |
| foreach ( $steps as $s ) { | |
| if ( isset( $s['type'] ) && 'wc_upsells' === $s['type'] ) { | |
| $anchor = absint( $s['id'] ); | |
| break; | |
| } | |
| } | |
| if ( $anchor <= 0 ) { | |
| $log( 'No anchor wc_upsells step in Store Checkout — aborting.' ); | |
| update_option( $run_key, 1, false ); | |
| return; | |
| } | |
| $all = get_posts( array( | |
| 'post_type' => $funnel_pt, | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => -1, | |
| 'fields' => 'ids', | |
| ) ); | |
| $added = 0; | |
| $insert_after = $anchor; | |
| foreach ( $all as $lf ) { | |
| $lf = absint( $lf ); | |
| if ( in_array( $lf, $step_ids, true ) ) { | |
| continue; // already a step here | |
| } | |
| // STANDALONE only — attached to no funnel. | |
| if ( 0 !== absint( get_post_meta( $lf, '_bwf_in_funnel', true ) ) ) { | |
| continue; | |
| } | |
| update_post_meta( $lf, '_bwf_in_funnel', $sc ); | |
| $ret = $funnel->add_step( 'wc_upsells', $lf, $insert_after ); | |
| $log( sprintf( | |
| 'added funnel %d "%s" as wc_upsells step after %d — add_step returned %s', | |
| $lf, get_the_title( $lf ), $insert_after, var_export( $ret, true ) | |
| ) ); | |
| $step_ids[] = $lf; | |
| $insert_after = $lf; // keep them in order | |
| $added ++; | |
| } | |
| // Re-read from DB to confirm persistence. | |
| $verify = new WFFN_Funnel( $sc ); | |
| $log( 'MOVE DONE. added=' . $added . ' | AFTER steps=' . wp_json_encode( $verify->get_steps() ) ); | |
| if ( class_exists( 'WooFunnels_Transient' ) ) { | |
| WooFunnels_Transient::get_instance()->delete_all_transients( 'upstroke' ); | |
| } | |
| update_option( $run_key, 1, false ); | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment