Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DeveloperWil/0decf69258a03d6a18eea8e8a6eac252 to your computer and use it in GitHub Desktop.
Save DeveloperWil/0decf69258a03d6a18eea8e8a6eac252 to your computer and use it in GitHub Desktop.
WooCommerce: Stripe product and customer metadata
/**
* Add Stripe metadata along with WooCommerce purchase
*
* @param $metadata
* @param $order
* @param $source
* @return mixed
*/
function wbdc_filter_wc_stripe_payment_metadata( $metadata, $order, $source ) {
/**
* Get order data
*/
$order_data = $order->get_data();
$metadata[ __( 'Billing Company', 'woocommerce-gateway-stripe' ) ] = sanitize_text_field( $order_data['billing']['company'] );
$metadata[ __( 'Customer Name', 'woocommerce-gateway-stripe' ) ] = sanitize_text_field( $order_data['billing']['first_name'] . ' ' . $order_data['billing']['last_name'] );
$metadata[ __( 'Customer Phone', 'woocommerce-gateway-stripe' ) ] = sanitize_text_field( $order_data['billing']['phone'] );
/**
* List products purchased
*/
$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', 'wbdc_filter_wc_stripe_payment_metadata', 10, 3 );
@githubuser5789
Copy link

Hello. I am trying to follow your tutorial here. Am I in the right place for the code discussed? I did not see the direct github link in the video description.

https://www.youtube.com/watch?v=I82v_QOgt9Y

Screenshot 2024-03-28 192905

@DeveloperWil
Copy link
Author

Hello. I am trying to follow your tutorial here. Am I in the right place for the code discussed? I did not see the direct github link in the video description.

https://www.youtube.com/watch?v=I82v_QOgt9Y

Screenshot 2024-03-28 192905

Yes, this is the code repository.

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