首页 > 解决方案 > PHP 重新排序

问题描述

我在 WooCommerce 中自定义结帐。

目前,我想重新订购在付款后立即显示的运输字段,而不是在摘要中。

在此处输入图像描述

正如您在底部图片中看到的,我尝试使用 jQuery 移动它, jQuery("#order_review > table > tfoot > tr.woocommerce-shipping-totals.shipping").appendTo("#payment > ul");

不幸的是,仅当我将其粘贴到开发人员控制台时才有效,当我在 WP 页面编辑器中将脚本应用于纯 JS 内容窗口时,它不起作用。

它是一个 tr 标签。 在此处输入图像描述

我试图用 PHP 将它移动到 functions.php 中,但我设法弄乱了整个网站,不得不重新构建它。所以我想我会寻求帮助。

谢谢你。

标签: phpwordpresswoocommerce

解决方案


考虑到您的 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;

}

推荐阅读