Home > OS >  WooCommerce - Adding Metadata to Stripe Payment
WooCommerce - Adding Metadata to Stripe Payment

Time:04-19

I'm trying to add tax metadata to the Stripe Payment Plugin after/during checkout with this code:

/*
* Add "Billing Company" value to Stripe metadata
*/
function filter_wc_stripe_payment_metadata( $metadata, $order, $source ) {

$order_data = $order->get_data();
$order_discount_total = $order_data['discount_total'];
$order_discount_tax = $order_data['discount_tax'];
$order_shipping_total = $order_data['shipping_total'];
$order_shipping_tax = $order_data['shipping_tax'];
$order_total = $order_data['cart_tax'];
$order_total_tax = $order_data['total_tax'];
    $metadata[ __( 'Discount Total', 'woocommerce-gateway-stripe' ) ] = $order_discount_total;
$metadata[ __( 'Discount Tax', 'woocommerce-gateway-stripe' ) ] =  $order_discount_tax;
$metadata[ __( 'Shipping Total', 'woocommerce-gateway-stripe' ) ] = $order_shipping_total;
$metadata[ __( 'Shipping Tax', 'woocommerce-gateway-stripe' ) ] = $order_shipping_tax;
$metadata[ __( 'Cart Tax', 'woocommerce-gateway-stripe' ) ] = $order_total;
$metadata[ __( 'Total Tax', 'woocommerce-gateway-stripe' ) ] = $order_total_tax;

    return $metadata;
}
add_filter( 'wc_stripe_payment_metadata', 'filter_wc_stripe_payment_metadata', 10, 3 );  

Using Stripe Test Mode, this meta data doesn't appear in the meta list.

From the API-Request that is passed to Stripe:

  "invoice": null,
  "livemode": false,
  "metadata": {
    "order_key": "wc_order_a7iTmZVNW52cz",
    "site_url": "https://xxxx.shop",
    "order_id": "2337",
    "payment_type": "single",
    "customer_email": "[email protected]",
    "customer_name": "Customer Name"
  },
  "on_behalf_of": null,
  "order": null,  

What am I missing?
The functions.php change doesn't even appear in the Woocommerce -> Status -> Stripe Logs. It's properly added into the functions.php, nothing else in it. Thanks

CodePudding user response:

/*
 * Add "Billing Company" value to Stripe metadata
 */

function filter_wc_stripe_payment_metadata($metadata, $order, $prepared_payment_method) {

    $order_discount_total = $order->get_discount_total();
    $order_discount_tax = $order->get_discount_tax();
    $order_shipping_total = $order->get_shipping_total();
    $order_shipping_tax = $order->get_shipping_tax();
    $order_total = $order->get_cart_tax();
    $order_total_tax = $order->get_total_tax();
    $metadata  = ['order_discount_total' => $order_discount_total];
    $metadata  = ['order_discount_tax' => $order_discount_tax];
    $metadata  = ['order_shipping_total' => $order_shipping_total];
    $metadata  = ['order_shipping_tax' => $order_shipping_tax];
    $metadata  = ['order_total' => $order_total];
    $metadata  = ['order_total_tax' => $order_total_tax];

    return $metadata;
}

add_filter('wc_stripe_payment_metadata', 'filter_wc_stripe_payment_metadata', 10, 3);
  • Related