Last active
February 19, 2024 22:49
-
-
Save stuartduff/8ac70799f0d4c3edd2e3a081cf0a4991 to your computer and use it in GitHub Desktop.
WooCommerce Stripe Add "Products" to Stripe Payment metadata
This file contains 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 "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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.