WooCommerce-将元数据添加到条纹付款中

发布于 2025-01-22 04:55:23 字数 1783 浏览 0 评论 0原文

我正在尝试使用此代码结帐后/结帐时将税收元数据添加到Stripe付款插件中:

/*
* 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重点:

  "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,  

我缺少什么?
functions.php更改甚至没有出现在WooCommerce中 - >状态 - >条纹日志。 它被正确添加到functions.php中,没有其他内容。谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不吻晚风 2025-01-29 04:55:23
/*
 * 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);
/*
 * 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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文