问题描述
我想通过我的functions.php文件中的一个片段来切换下面代码中“ Billing City”和“ Billing ZIP”字段的顺序。我已经坚持了几个小时,但是我做对了。这是easy-digital-downloads / includes / checkout / template.php文件中的代码,非常感谢您的帮助:
p <- function
解决方法
好吧,根据您的评论,我会说,实现这一目标的最简单(不是最干净的)方法是包括一小段JS来移动DIV
$("#edd-card-zip-wrap").insertBefore("#edd-card-city-wrap");
应该足够了:)
编辑: 将此代码粘贴到主题的functions.php
中add_action( 'wp_enqueue_scripts','enqueue_my_script' );
function enqueue_my_script() {
wp_enqueue_script( 'my-custom-script',get_stylesheet_directory_uri() . '/my-script.js',array( "jquery" ),false,true );
}
这将搜索名为“ my-script.js”的文件,该文件位于主题的根文件夹中(与functions.php文件相同级别) 该文件内容可以是这样的:
使用固定的等待时间进行编辑:
$("document").ready(function() {
var waitThisTime = 1000; // Wait this ms. 1000ms = 1sec
setTimeout(function(){
$("#edd-card-zip-wrap").insertBefore("#edd-card-city-wrap");
},waitThisTime);
});
,
您可以通过使用以下代码段来做到这一点。
add_filter( 'woocommerce_checkout_fields','ro_postcode_city_interchange' );
function ro_postcode_city_interchange( $checkout_fields ) {
$checkout_fields['billing']['billing_postcode']['priority'] = 70;
$checkout_fields['billing']['billing_city']['priority'] = 90;
return $checkout_fields;
}
此代码截取器将交换顺序,因为所有字段都有其优先级,因此在这里您必须给postcode
的{{1}}优先级和city
的{{1}}优先级。>
经过测试,效果很好。