在Woocommerce购物车和结帐页面中以不同方式重新排序多项费用 [英] Reordering multiple fees differently in Woocommerce cart and checkout pages

查看:131
本文介绍了在Woocommerce购物车和结帐页面中以不同方式重新排序多项费用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在woocommerce的结帐中添加多个费用时,是否可以优先考虑其顺序?目前看来woocommerce是根据费用值对它们进行订购的,因此,例如:费用1 =£10.00,费用2 =£20.00,它们将像这样被订购:

When adding multiple fees to the checkout in woocommerce, is it possible to prioritise the order of them? Currently it looks like woocommerce orders them by the fee value, so for example: Fee 1 = £10.00, Fee 2 = £20.00, they would get ordered like so:


  • 小计

  • 费用2 =£20.00

  • 费用1 =£10.00

  • 总计

  • Subtotal
  • Fee 2 = £20.00
  • Fee 1 = £10.00
  • Total

是否可以自定义订单?也许对费用附加的操作添加了优先级?我希望 Fee 2 始终是最后的费用项目。

Is it possible to have a custom order at all? Maybe adding a priority to the action the fee is attached to? I would like Fee 2 to always be the last fee item.

这可以实现吗?

推荐答案

在Woocommerce中,费用由 WC_Cart_Fee 类,如果您查看 get_fees() 方法,您会在 sort_fees_callback() uasort() php排序功能。

In Woocommerce Fees are handled by the WC_Cart_Fee class and if you look to the source code of get_fees() method, you will see that sorting is made by fee amount in sort_fees_callback() with uasort() php sorting function.


对购物车和结帐页面中显示的费用进行不同排序的唯一方法通过活动子主题(或活动主题)

1)按名称对费用分类:首先,这是一个自定义函数,用于按标签名称对费用进行分类:

1) Sorting Fees by name: First here is a custom function to sort fees by their label name:

function wc_get_sorted_fees(){
    $fees = WC()->cart->get_fees();
    ksort($fees);
    return $fees;
}

代码进入活动子主题(或活动主题)的function.php文件。经过测试并且可以正常工作。

Code goes in function.php file of your active child theme (or active theme). Tested and works.

2)显示-覆盖模板 cart / cart-totals.php checkout / review-order.php

在两个模板文件中,您将替换以下行:

In both templates files you will replace the line:

<?php foreach ( WC()->cart->get_fees() as $fee ) : ?>

作者

<?php foreach ( wc_get_sorted_fees() as $fee ) : ?>




相关:在WooCommerce订单和电子邮件通知上按名称排序费用

这篇关于在Woocommerce购物车和结帐页面中以不同方式重新排序多项费用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆