Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created February 20, 2026 12:30
Show Gist options
  • Select an option

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

Select an option

Save xlplugins/7562c09c20e9ec05f733022de9af6143 to your computer and use it in GitHub Desktop.
FKWCS Upsell Stripe Intent Update
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'wfocu_offer_new_order_created', 'fkwcs_update_stripe_intent_for_upsell_order', 20, 2 );
function fkwcs_update_stripe_intent_for_upsell_order( $new_order, $txn_id ) {
try {
if ( ! $new_order instanceof WC_Order ) {
return;
}
$intent_meta = \FKWCS\Gateway\Stripe\Helper::get_meta( $new_order, '_fkwcs_intent_id' );
$intent_id = is_array( $intent_meta ) ? ( $intent_meta['id'] ?? '' ) : '';
if ( empty( $intent_id ) || 0 !== strpos( $intent_id, 'pi_' ) ) {
return;
}
$gateway = WC()->payment_gateways()->payment_gateways()[ $new_order->get_payment_method() ] ?? WC()->payment_gateways()->payment_gateways()['fkwcs_stripe'] ?? null;
if ( ! $gateway || ! method_exists( $gateway, 'add_metadata' ) ) {
return;
}
$offer = function_exists( 'WFOCU_Core' ) ? WFOCU_Core()->data->get( 'current_offer' ) : '';
$desc = apply_filters( 'fkwcs_get_order_description', sprintf( __( '%1$s - Order %2$s - 1 click upsell: %3$s', 'funnelkit-stripe-woo-payment-gateway' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $new_order->get_order_number(), $offer ?: __( 'Upsell', 'funnelkit-stripe-woo-payment-gateway' ) ), $new_order );
$meta = array_map( 'strval', apply_filters( 'wc_fkwcs_stripe_payment_metadata', array_merge( $gateway->add_metadata( $new_order ), array( 'fk_upsell' => 'yes' ) ), $new_order, null ) );
$res = $gateway->set_client_by_order_payment_mode( $new_order )->payment_intents( 'update', array( $intent_id, array( 'description' => $desc, 'metadata' => $meta ) ) );
if ( empty( $res['success'] ) ) {
\FKWCS\Gateway\Stripe\Helper::log( 'FKWCS Upsell Intent Update failed: ' . ( $res['message'] ?? 'Unknown' ) );
}
} catch ( \Exception $e ) {
\FKWCS\Gateway\Stripe\Helper::log( 'FKWCS Upsell Intent Update exception: ' . $e->getMessage() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment