Skip to content

Instantly share code, notes, and snippets.

@stuartduff
Last active February 19, 2024 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartduff/8ac70799f0d4c3edd2e3a081cf0a4991 to your computer and use it in GitHub Desktop.
Save stuartduff/8ac70799f0d4c3edd2e3a081cf0a4991 to your computer and use it in GitHub Desktop.
WooCommerce Stripe Add "Products" to Stripe Payment metadata
/*
* Add "Products" to Stripe metadata
*/
function filter_wc_stripe_payment_metadata( $metadata, $order, $source ) {
$count = 1;
foreach( $order->get_items() as $item_id => $line_item ){
$item_data = $line_item->get_data();
$product = $line_item->get_product();
$product_name = $product->get_name();
$item_quantity = $line_item->get_quantity();
$item_total = $line_item->get_total();
$metadata['Line Item '.$count] = 'Product name: '.$product_name.' | Quantity: '.$item_quantity.' | Item total: '. number_format( $item_total, 2 );
$count += 1;
}
return $metadata;
}
add_filter( 'wc_stripe_payment_metadata', 'filter_wc_stripe_payment_metadata', 10, 3 );
@bryanm1990
Copy link

I need to add the product name as metadata in stripe, I followed the steps in this tutorial and everything worked very well until 5 days ago when I updated woocommerce and it stopped working, it doesn't give any errors, it just doesn't show the metadata anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment