• Resolved careyrob

    (@careyrob)


    I use this plugin with Stripe and overall I’m happy with it, but I’ve had to apply some changes so that the manual payments have all of the same transaction metadata in Stripe as those that are processed through self-service checkout in my store.

    I have to modify the following transaction metadata labels:
    ‘Customer Name’ => ‘customer_name’
    ‘Customer Email’ => ‘customer_email’

    I have to add the following transaction metadata labels:
    ‘order_id’
    ‘invoice_id’

    The code I use looks like this:
    $charge_info[‘metadata’][‘customer_name’] = $name;
    $charge_info[‘metadata’][‘customer_email’] = $email;
    $charge_info[‘metadata’][‘order_id’] = $order_id;
    $charge_info[‘metadata’][‘invoice_id’] = $order_id;

    I also need to update the transaction description string so that it reads:
    [‘blogname’] – Invoice [$order_id]

    I used the Manual Payment “Settings” tab to enter the following transaction description, but it doesn’t flow through to the stripe metadata and it wouldn’t include the $order_id.
    “SkillWorks, Inc. – Invoice ”

    Here is the transaction description code from the Stripe plugin (I replaced “Order” with “Invoice”):

    $post_data[‘description’] = sprintf( __( ‘%1$s – Invoice %2$s’, ‘woocommerce-gateway-stripe’ ), wp_specialchars_decode( get_bloginfo( ‘name’ ), ENT_QUOTES ), $order->get_order_number() );

    It’s a pain to manually reapply these corrections each time there is a new version of woo mp released.

    Is there a way that I could add a code snippet that:
    1. overrides the transaction metadata labels for Customer Name and Customer Email
    2. adds order_id and invoice_id to the transaction metadata
    3. overrides the default transaction description to use my preferred format

    Would this allow me to just update the woo mp plugin when a new version is available without changing code each time?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author bfl

    (@bfl)

    Hey @careyrob. I’ll release an update soon that will add support for such snippets. I’ll reply to this thread when it’s ready and I’ll provide a code snippet that will automatically apply your customizations.

    Plugin Author bfl

    (@bfl)

    Hey @careyrob. I’ve released the update. Here’s the code snippet that will apply your customizations:

    add_filter( 'woo_mp_stripe_charge_request', function ( $request, $order ) {
    	$request['description'] = sprintf(
    		'%1$s – Invoice %2$s',
    		wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
    		$order->get_order_number()
    	);
    
    	$request['metadata'] = [
    		'customer_name'  => sanitize_text_field( $order->get_billing_first_name() ) . ' ' . sanitize_text_field( $order->get_billing_last_name() ),
    		'customer_email' => sanitize_email( $order->get_billing_email() ),
    		'order_id'       => $order->get_order_number(),
    		'invoice_id'     => $order->get_order_number(),
    	];
    
    	return $request;
    }, 10, 2 );

    You can add this snippet to your theme’s functions.php file or wherever you usually put your customizations. I’ve copied the code for the description and the metadata from the official WooCommerce Stripe Payment Gateway plugin, so it should be exactly the same. However if the relevant code in that plugin changes, you’ll need to update the snippet accordingly.

    Thread Starter careyrob

    (@careyrob)

    Thank you @bfl!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Edit Stripe transaction description and metadata’ is closed to new replies.