WooCommerce - 将元数据添加到条纹支付
WooCommerce - Adding Metadata to Stripe Payment
我正在尝试使用以下代码将税务元数据添加到 Stripe 支付插件 after/during 结帐:
/*
* 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 );
使用条带测试模式,此元数据不会出现在元列表中。
来自 API-传递给 Stripe 的请求:
"invoice": null,
"livemode": false,
"metadata": {
"order_key": "wc_order_a7iTmZVNW52cz",
"site_url": "https://xxxx.shop",
"order_id": "2337",
"payment_type": "single",
"customer_email": "xxx@xxx-xxx.de",
"customer_name": "Customer Name"
},
"on_behalf_of": null,
"order": null,
我错过了什么?
functions.php 更改甚至没有出现在 Woocommerce -> 状态 -> Stripe 日志中。
它已正确添加到 functions.php 中,没有其他内容。谢谢
/*
* 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);
我正在尝试使用以下代码将税务元数据添加到 Stripe 支付插件 after/during 结帐:
/*
* 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 );
使用条带测试模式,此元数据不会出现在元列表中。
来自 API-传递给 Stripe 的请求:
"invoice": null,
"livemode": false,
"metadata": {
"order_key": "wc_order_a7iTmZVNW52cz",
"site_url": "https://xxxx.shop",
"order_id": "2337",
"payment_type": "single",
"customer_email": "xxx@xxx-xxx.de",
"customer_name": "Customer Name"
},
"on_behalf_of": null,
"order": null,
我错过了什么?
functions.php 更改甚至没有出现在 Woocommerce -> 状态 -> Stripe 日志中。
它已正确添加到 functions.php 中,没有其他内容。谢谢
/*
* 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);