【问题标题】:WooCommerce get Stripe Fee of OrderWooCommerce 获得 Stripe 订单费用
【发布时间】:2019-06-27 07:10:40
【问题描述】:

我需要通过代码获取订单费用。 有两种可能的费用:stripe 和 paypal。

条纹费用保存在订单元中:_stripe_fee

我需要得到里面的金额。 或者:所有可能的费用(paypal 和 stripe)。

虽然我可以获取元字段,但我真的不想硬编码字段名。

有没有办法收取订单的所有费用?

我尝试过这样:

$order = wc_get_order( 8012 );

var_dump($order->get_fees());

但是数组是空的。

但是

var_dump($order)

表明有条带费(后端和数据库也这么说)

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    所以,理论上$order->fees() 应该退费。它通过返回数组fee_line 来做到这一点。不幸的是,Stripe 和 Paypal 似乎都没有写信给 thatfee_line。相反,他们写入元属性。

    这并不会阻止您使用自己的函数来返回 Stripe 或 Paypal 费用:

    function get_order_fees(WCOrder $order) {
    
        switch(true) {
            // get fees from Stripe, if exists
            case $fees = $order->get_meta("_stripe_fee");
                break;
            // get fees from Paypal, if exists
            case $fees = $order->get_meta("_paypal_transaction_fee"):
               break;
            // otherwise fee is 0
            default:
                $fees = 0;
                break;
        }
    
        return $fees;
    }
    

    【讨论】:

    • 谢谢。我希望有一个更通用的解决方案。像 > 是否有费用(Stripe 或 Paypal),如果有,请给我,无需获取元数据。什么是 get_fees() 函数,即使是...
    • 我找不到get_fees() 方法的任何文档。你在哪里找到的?
    • 在这里找到:[链接]docs.woocommerce.com/wc-apidocs/…
    • 我做了一些研究并更新了答案。看看这是否有帮助。
    • 你太棒了!谢谢:)
    猜你喜欢
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 2018-07-09
    • 2018-10-27
    • 2015-11-27
    • 2014-12-22
    • 2015-08-21
    相关资源
    最近更新 更多