php - PHP 重新排序
问题描述
我在 WooCommerce 中自定义结帐。
目前,我想重新订购在付款后立即显示的运输字段,而不是在摘要中。
正如您在底部图片中看到的,我尝试使用 jQuery 移动它,
jQuery("#order_review > table > tfoot > tr.woocommerce-shipping-totals.shipping").appendTo("#payment > ul");
不幸的是,仅当我将其粘贴到开发人员控制台时才有效,当我在 WP 页面编辑器中将脚本应用于纯 JS 内容窗口时,它不起作用。
我试图用 PHP 将它移动到 functions.php 中,但我设法弄乱了整个网站,不得不重新构建它。所以我想我会寻求帮助。
谢谢你。
解决方案
考虑到您的 jquery 方法,我认为问题可能在于执行该 JS 时页面未完全加载。你的代码应该是这样的:
$( document ).ready(function() {
jQuery("#order_review > table > tfoot > tr.woocommerce-shipping-totals.shipping").appendTo("#payment > ul");
});
如果您想在 PHP 中执行此操作,我认为此链接可能会有所帮助。正如我发现你想将一个字段移动到另一个字段组,可以这样做:
add_filter( 'woocommerce_checkout_fields', 'misha_billing_email_another_group' );
function misha_billing_email_another_group( $checkout_fields ){
// 1. We assign a field array to another group here
$checkout_fields['order']['billing_email'] = $checkout_fields['billing']['billing_email'];
// 2. Remove a field from a previous location
unset( $checkout_fields['billing']['billing_email'] );
return $checkout_fields;
}
推荐阅读
- import - 自定义 GA 数据成本 = 缺少 Analytics API 列?
- python - Cloud Function 为 bigquery 客户端抛出错误类型错误,但在 Jupyter Notebook 上工作正常
- javascript - 窗口加载和点击事件
- c# - 例如,C# 为什么我不能将字符串从 networkstream 解析为 int?TCP客户端.服务器
- javascript - 加载页面时自动打开输入文件对话框
- python - 如何使用 pyspark 读取包含多行的 .sql 文件?
- python - 带代理的 Selenium 返回空网站
- c# - 将所有活动从一条记录移动到另一条记录,SSIS 还是 C#?
- postgresql - 如何在 Go API 中同时运行函数而不是顺序运行?
- html - 如何分隔 HTML 列表中的项目,使其在水平导航中就像三个元素在一侧,两个在另一侧