Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Support James Hunt

    (@bonkerz)

    @davidecho Yes that can be fixed. From 1.0.7 we allow you to exclude meta fields via a filter. Here is an example of how to exclude _stripe_intent_id from the clone.

    You can add this to your theme via functions.php or insert in to your site via a Code Snippets plugin.

    /**
    * Exclude Stripe intent ID from cloned order meta keys.
    *
    * @param array $ignore_meta_keys Array of meta keys to ignore.
    * @param int $original_order_id The ID of the original order being cloned.
    * @param WC_Order $original_order The original order object being cloned.
    * @return array Modified array of meta keys to ignore.
    */
    function ymmv_exclude_stripe_intent_id_from_clone( $ignore_meta_keys, $original_order_id, $original_order ) {
    if ( ! is_array( $ignore_meta_keys ) ) {
    $ignore_meta_keys = array();
    }

    if ( ! in_array( '_stripe_intent_id', $ignore_meta_keys, true ) ) {
    $ignore_meta_keys[] = '_stripe_intent_id';
    }

    return $ignore_meta_keys;
    }
    add_filter( 'cdo_wc_clone_order_ignore_meta_keys', 'ymmv_exclude_stripe_intent_id_from_clone', 10, 3 );

    If the meta field is called something else you can just update the above code to reflect the meta field you want to exclude.

    Hope that helps!

    Plugin Support James Hunt

    (@bonkerz)

    @davidecho As I’ve not heard from you on this, will presume this is fixed! Feel free to reach out if you have any other questions or issues.

    My solution, end-to-end…

    1. To avoid Level 3 pricing mismatch errors: 1) Stripe does not reject orders 2) No random payment failures and 3) Checkout works consistently.

      // Disable Stripe Level 3 data for all WooCommerce Stripe payments.

      add_filter( ‘wc_stripe_generate_create_intent_request’, ‘tofw_disable_stripe_level3’, 20, 3 );
      function tofw_disable_stripe_level3( $request, $order, $prepared_source ) {
      // If Level 3 data is present, remove it so Stripe never validates it.
      if ( isset( $request[‘level3’] ) ) {
      unset( $request[‘level3’] );
      }
      return $request;
      }

      2. And to clone paid orders: Clone starts clean, No PaymentIntent carried over, No Stripe aborts, No manual cleanup, and Payments work immediately.

      /*
      TOFW: Make cloned orders Stripe-clean.
      Uses the official cdo_wc_clone_order_ignore_meta_keys filter from “Clone / Duplicate Orders for WooCommerce” to prevent copying Stripe payment intent / charge / fee meta to the new cloned order.
      */

      function tofw_exclude_stripe_meta_from_clone( $ignore_meta_keys, $original_order_id, $original_order ) {
      if ( ! is_array( $ignore_meta_keys ) ) {
      $ignore_meta_keys = array();
      }
      // Meta keys that should NOT be copied to cloned orders.
      // _stripe_intent_id is the critical one for avoiding “transaction already consumed” on clones.
      $stripe_keys_to_ignore = array(
      ‘_stripe_intent_id’, // PaymentIntent ID – MUST be ignored on clones.
      ‘_stripe_charge_id’, // Charge ID – avoid clones tying to original charge for refunds.
      ‘_stripe_customer_id’, // Customer ID – optional, but keeps clones cleaner.
      ‘_stripe_upe_saved_payment_method’, // Saved payment method token.
      ‘_stripe_mode’, // Live/test mode flag from original.
      ‘_stripe_balance_transaction’, // Balance transaction reference.
      ‘_stripe_fee’, // Fee meta from original order.
      ‘_stripe_net’, // Net payout meta from original order.
      ‘_stripe_total_fee’,
      ‘_stripe_total_net’,
      );
      foreach ( $stripe_keys_to_ignore as $meta_key ) {
      if ( ! in_array( $meta_key, $ignore_meta_keys, true ) ) {
      $ignore_meta_keys[] = $meta_key;
      }
      }
      return $ignore_meta_keys;
      }
      add_filter( ‘cdo_wc_clone_order_ignore_meta_keys’, ‘tofw_exclude_stripe_meta_from_clone’, 10, 3 );

      Thread Starter davidecho

      (@davidecho)

      Hi @bonkerz , yes this is fixed.

      I have another request, how can I include copying the payment method when I clone the order?

      Snippet: keep payment method on cloned orders: Add this as a new snippet (Run everywhere).

      /* WooCommerce ~ Clone Orders ~ Preserve Payment Method – When cloning an order, allow _payment_method and _payment_method_title to be copied to the new order so the gateway is preselected on the clone. */

      add_filter( ‘cdo_wc_clone_order_ignore_meta_keys’, function( $ignore_meta_keys, $original_order_id, $original_order ) {
      if ( ! is_array( $ignore_meta_keys ) ) {
      $ignore_meta_keys = array();
      }
      // Meta keys we want to ALLOW on clones.
      $allow_keys = array(
      ‘_payment_method’,
      ‘_payment_method_title’,
      );
      // Remove the allowed keys from the ignore list.
      $ignore_meta_keys = array_values(
      array_diff( $ignore_meta_keys, $allow_keys )
      );
      return $ignore_meta_keys;
      }, 20, 3 );

      What this does:
      > The cloner builds its default $ignore_meta_keys (which includes _payment_method and _payment_method_title).
      > This filter runs and removes those two from the ignore array.
      > Result: when you clone an order:
      >>The new order does get _payment_method (e.g. stripe) and _payment_method_title copied.
      >>But your other snippet still ensures no _stripe_intent_id or other Stripe transaction meta is copied.

      So:
      > Cloned order will show Stripe already selected as the payment method.
      > Cloned order will not be tied to the old PaymentIntent.
      > Your two existing active snippets remain:
      >> Disable Level 3 Data (prevents the Level 3 mismatch error).
      >> Ensure Cloned Orders are Stripe-Clean (adds Stripe meta to the ignore list).

      Important functional warning:
      > This (untested) snippet (preserve payment method) works alone
      > Cloning paid orders safely requires the Stripe-clean snippet active
      > Level 3 snippet is optional but recommended

      Plugin Support James Hunt

      (@bonkerz)

      @sysquest Thanks for this snippet for Davids problem, I appreciate it.

      I think from the next version we will exclude a lot of these keys by default, as I think 99.9% of users will never need these copied and will just mess up any Stripe transaction.

      I am proposing here to exclude the following by default on a cloned order

      	// Transaction-binding identifiers.
      '_stripe_intent_id',
      '_stripe_charge_id',
      '_stripe_balance_transaction',
      '_stripe_mandate',

      // Per-charge financials.
      '_stripe_fee',
      '_stripe_net',
      '_stripe_total_fee',
      '_stripe_total_net',
      '_stripe_currency',

      // Stored method & customer bindings.
      '_stripe_customer_id',
      '_stripe_source_id',
      '_stripe_card_id',
      '_stripe_upe_saved_payment_method',
      '_stripe_payment_method_type',

      // Misc flags.
      '_stripe_mode',

      Let me know your thoughts. If users want to bring them back they can use a similar method to the above to bring them back, but this will improve cloning by default for all users. What do you think?

      Hi James,

      Really appreciate the follow-through and the thoughtful update. Your proposed default exclusions are absolutely the right direction – and honestly, they align perfectly with what we discovered in troubleshooting.

      Cloned orders should never inherit transaction-bound Stripe data. Every one of the keys you listed represents either a previously-consumed PaymentIntent, a charge reference, a customer token, or financial metadata tied to a different order. Pulling those into a clone doesn’t just cause edge-case issues… it guarantees unpredictable behavior for users who aren’t expecting it.

      Excluding the full set by default is a smart and safe move. Anyone who truly needs those keys copied (which will be a fraction of a fraction of users) has a clear, documented way to restore them via your filter.

      From my perspective, this change:
      > Dramatically improves reliability for everyone
      > Eliminates the most common Stripe error that appears on cloned paid orders
      > Keeps reporting data accurate
      > Reduces support load for both sides
      > Makes cloning behave exactly the way users “expect” without surprises

      So yes, I’m completely on board. This will make cloning far more intuitive for your entire user base, and it future-proofs Stripe integration in a way that just makes sense.

      Thanks again for the quick response and the willingness to refine the plugin at this level. It’s great seeing this evolve in real time.

      Plugin Support James Hunt

      (@bonkerz)

      @sysquest The default fields have now been updated in v1.0.10, which has just been released 🙂 this should make your code a bit more streamlined without the need to purposely filter out the Stripe meta. Thanks for your insights and work on this!

      Thread Starter davidecho

      (@davidecho)

      Hi @bonkerz @sysquest,

      Thank you for this I added the code below

      /* WooCommerce ~ Clone Orders ~ Preserve Payment Method */
      add_filter( 'cdo_wc_clone_order_ignore_meta_keys', function( $ignore_meta_keys, $original_order_id, $original_order ) {
      if ( ! is_array( $ignore_meta_keys ) ) {
      $ignore_meta_keys = array();
      }

      // Keys to ensure are NOT ignored
      $allow_keys = array(
      '_payment_method',
      '_payment_method_title',
      );

      // Remove allowed keys from ignore list
      foreach ( $allow_keys as $key ) {
      if ( in_array( $key, $ignore_meta_keys, true ) ) {
      $ignore_meta_keys = array_diff( $ignore_meta_keys, array( $key ) );
      }
      }

      return $ignore_meta_keys;

      }, 999, 3 ); // Run last, after all other filters

      I was expecting to get the same payment method on the cloned order but I am not seeing it. Am I missing something. Please refer to the screenshot below:
      https://imgur.com/a/WjErjxN

      Thread Starter davidecho

      (@davidecho)

      Hi @bonkerz,

      Just want to check in if you’ve seen my above request. I’ve added the code but the payment method are still not copied through when an order is duplicated.

      Plugin Support James Hunt

      (@bonkerz)

      @davidecho Yes seen it – I am trying to work out your use case.

      Currently, we have code that runs after the meta filter which always removes the payment method and title. This is why your filter has no effect for these fields.

      During a normal order process, the payment method and title are only assigned after a payment routine is completed, so cloning these fields, to me, doesn’t sound useful, could be very confusing, and this is why we hard code their removal.

      I think I can rewrite the code to be more flexible and so that the payment method and title is cloned, but I would love to know your use case and why you want this info cloned, it would help me understand and make sure the plugin fits all needs.

      Plugin Support James Hunt

      (@bonkerz)

      @davidecho I’ve released a new version 1.0.11 which should now allow you to keep the title and method.

      Just to summarise: from this thread we developed a list of “do not clone” meta keys which applies to all users by default. These can be edited and updated by using cdo_wc_clone_order_ignore_meta_keys filter.

      David asked to be able to retain the payment title and method in a clone, which was previously hard-coded to always be removed. This can now be done by using the existing filter and the following snippet example in functions.php/theme/mu-plugin should do it:

      function ymmv_custom_allow_payment_meta_cloning( $ignore_keys ) {
      // Specify the keys you want to keep.
      $keys_to_allow = array(
      '_payment_method',
      '_payment_method_title',
      );

      // Remove the keys from the ignore list array if they exist.
      $ignore_keys = array_diff( $ignore_keys, $keys_to_allow );

      return $ignore_keys;
      }
      add_filter( 'cdo_wc_clone_order_ignore_meta_keys', 'ymmv_custom_allow_payment_meta_cloning', 10, 1 );
    Viewing 12 replies - 1 through 12 (of 12 total)

    You must be logged in to reply to this topic.