从 WooCommerce 结帐管理器中的其他结帐字段更改订单
Change the order from additional checkout fields in WooCommerce checkout manager
在 Woocommerce 中,我想更改使用 WooCommerce checkout manager plugin 创建的其他结帐字段顺序(以编程方式)。这就是我实际拥有的:
我需要在 'Format' 字段之后更改 'Rolls per Carton' 字段的顺序。
感谢任何帮助。
WooCommerce 结帐管理器插件不允许重新排序其他字段,并且它会将该数据保存在他的一些选项设置中。
所以方法是只更改一次插件设置。
To run the following code, just browse any page of your web site.
You will run it just once and then remove it.
代码:
function wccs_change_fields_order(){
$wccs_settings = get_option( 'wccs_settings' );
// Get the array of additional fields
$additional_fields = $wccs_settings['buttons'];
// SETTINGS: Here set your 2 product attribute Names
$format = 'Format';
$rp_carton = 'Rolls per Carton';
// FIRST Loop Get the array key for 'Rolls per Carton' field label
foreach( $additional_fields as $key => $field ){
if( $field['label'] == $rp_carton )
$key_rp_carton = $key;
}
// Save 'Rolls per Carton' data field in a variable
$field_rp_carton = $additional_fields[$key_rp_carton];
// Remove 'Rolls per Carton' data field from the fields array
unset($additional_fields[$key_rp_carton]);
// Initializing variables
$new_additional_fields = array();
$sorting_index = 1;
// SECOND Loop reordering fields
foreach( $additional_fields as $key => $field ){
// Update "order" argument
$field['order'] = $sorting_index;
// Add the current field to a new array
$new_additional_fields[] = $field;
$sorting_index++; // Increment sorting index
// When we reach 'Format' data field
if( $field['label'] == $format ){
// Set a new position to 'Rolls per Carton' attribute
$field_rp_carton['order'] = $sorting_index;
// Add 'Rolls per Carton' field data in the new array
$new_additional_fields[] = $field_rp_carton;
$sorting_index++; // Increment sorting index
}
}
// Set back the reordered additional fields in the main array
$wccs_settings['buttons'] = $new_additional_fields;
// Update the new changed options (Save)
update_option( 'wccs_settings', $wccs_settings, 'yes' );
}
wccs_change_fields_order();
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
在 Woocommerce 中,我想更改使用 WooCommerce checkout manager plugin 创建的其他结帐字段顺序(以编程方式)。这就是我实际拥有的:
我需要在 'Format' 字段之后更改 'Rolls per Carton' 字段的顺序。
感谢任何帮助。
WooCommerce 结帐管理器插件不允许重新排序其他字段,并且它会将该数据保存在他的一些选项设置中。
所以方法是只更改一次插件设置。
To run the following code, just browse any page of your web site.
You will run it just once and then remove it.
代码:
function wccs_change_fields_order(){
$wccs_settings = get_option( 'wccs_settings' );
// Get the array of additional fields
$additional_fields = $wccs_settings['buttons'];
// SETTINGS: Here set your 2 product attribute Names
$format = 'Format';
$rp_carton = 'Rolls per Carton';
// FIRST Loop Get the array key for 'Rolls per Carton' field label
foreach( $additional_fields as $key => $field ){
if( $field['label'] == $rp_carton )
$key_rp_carton = $key;
}
// Save 'Rolls per Carton' data field in a variable
$field_rp_carton = $additional_fields[$key_rp_carton];
// Remove 'Rolls per Carton' data field from the fields array
unset($additional_fields[$key_rp_carton]);
// Initializing variables
$new_additional_fields = array();
$sorting_index = 1;
// SECOND Loop reordering fields
foreach( $additional_fields as $key => $field ){
// Update "order" argument
$field['order'] = $sorting_index;
// Add the current field to a new array
$new_additional_fields[] = $field;
$sorting_index++; // Increment sorting index
// When we reach 'Format' data field
if( $field['label'] == $format ){
// Set a new position to 'Rolls per Carton' attribute
$field_rp_carton['order'] = $sorting_index;
// Add 'Rolls per Carton' field data in the new array
$new_additional_fields[] = $field_rp_carton;
$sorting_index++; // Increment sorting index
}
}
// Set back the reordered additional fields in the main array
$wccs_settings['buttons'] = $new_additional_fields;
// Update the new changed options (Save)
update_option( 'wccs_settings', $wccs_settings, 'yes' );
}
wccs_change_fields_order();
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。