我想在woocommerce产品管理部分的下拉列表中按特定顺序显示“属性”
我想在woocommerce产品管理部分的下拉列表中按特定顺序显示属性。属性未按正确顺序输入。现在重做已经太晚了,所以我想在下拉菜单中按它们应该出现的样子列出它们。输入数据的人上下滚动此列表太耗时。如果它们已经按正确的顺序排列,速度会更快。我已经看到了如何强制它们在前端按特定顺序显示,但不在管理部分-谢谢只需转到 产品->属性 ,选择要重新排序的属性。然后单击“配置术语”图标。在这里,您将看到所有属性项。只需按所需顺序拖放即可。提示: 直接去 产品->属性 ,选择要重新排序的属性。然后单击“配置术语”图标。在这里,您将看到所有属性项。只需按所需顺序拖放即可。提示:我想在woocommerce产品管理部分的下拉列表中按特定顺序显示“属性”,woocommerce,Woocommerce,我想在woocommerce产品管理部分的下拉列表中按特定顺序显示属性。属性未按正确顺序输入。现在重做已经太晚了,所以我想在下拉菜单中按它们应该出现的样子列出它们。输入数据的人上下滚动此列表太耗时。如果它们已经按正确的顺序排列,速度会更快。我已经看到了如何强制它们在前端按特定顺序显示,但不在管理部分-谢谢只需转到 产品->属性 ,选择要重新排序的属性。然后单击“配置术语”图标。在这里,您将看到所有属性项。只需按所需顺序拖放即可。提示: 直接去 产品->属性 ,选择要重新排序的属性。然后单击“配置
运行此代码一次,然后将其删除。因此,将其加载到插件中,激活插件,然后停用。我曾考虑过自动停用或创建一个运行一次的瞬态,但我会让你处理它。如果代码在第一次出现错误,那么这些问题实际上会很麻烦 也许您可以调整第二个功能,使其也可以在save_post或replace上运行,以防将来商店经理以错误的顺序添加属性。实际上,有一个名为的过滤器,允许您在每次更新帖子和保存元数据时一致地应用此过滤器 警告:备份您的数据库!这段代码是破坏性的,将永久性地改变您的数据库,除了在演示阵列上看到新的排序函数外,还没有进行过测试。使用风险自负
function so_35733629_update_products(){
$args = array(
'posts_per_page' => -1,
'meta_value' => '',
'post_type' => 'product',
'post_status' => 'any',
);
$products_array = get_posts( $args );
foreach( $products_array as $product ){
$attributes = get_post_meta( $product->ID, '_product_attributes', true );
if( ! empty( $atttributes ) ){
$attributes = so_35733629_reorder_attributes( $attributes );
update_post_meta( $product->ID, '_product_attributes', $attributes );
}
}
}
add_action( 'admin_init', 'so_35733629_update_products' );
function so_35733629_reorder_attributes( $attributes ){
// here is the desired order
$order = array(
'pa_maker',
'pa_model-name',
'pa_man-lady',
'pa_model-case-ref',
'pa_case-serial'
);
$new_attributes = array();
// create new array based on order of $order array
foreach( $order as $key ){
if( isset( $attributes[$key] ) ){
// add to new attributes array
$new_attributes[$key] = $attributes[$key];
// remove from the attributes array
unset( $attributes[$key] );
}
}
// merge any leftover $attributes in at the end so we don't accidentally lose anything
$new_attributes = array_merge( $new_attributes, $attributes );
// set the new position keys
$i = 0;
foreach( $new_attributes as $key => $attribute ){
// update the position
$new_attributes[$key]['position'] = $i;
$i++;
}
return $new_attributes;
}
运行此代码一次,然后将其删除。因此,将其加载到插件中,激活插件,然后停用。我曾考虑过自动停用或创建一个运行一次的瞬态,但我会让你处理它。如果代码在第一次出现错误,那么这些问题实际上会很麻烦 也许您可以调整第二个功能,使其也可以在save_post或replace上运行,以防将来商店经理以错误的顺序添加属性。实际上,有一个名为的过滤器,允许您在每次更新帖子和保存元数据时一致地应用此过滤器 警告:备份您的数据库!这段代码是破坏性的,将永久性地改变您的数据库,除了在演示阵列上看到新的排序函数外,还没有进行过测试。使用风险自负
function so_35733629_update_products(){
$args = array(
'posts_per_page' => -1,
'meta_value' => '',
'post_type' => 'product',
'post_status' => 'any',
);
$products_array = get_posts( $args );
foreach( $products_array as $product ){
$attributes = get_post_meta( $product->ID, '_product_attributes', true );
if( ! empty( $atttributes ) ){
$attributes = so_35733629_reorder_attributes( $attributes );
update_post_meta( $product->ID, '_product_attributes', $attributes );
}
}
}
add_action( 'admin_init', 'so_35733629_update_products' );
function so_35733629_reorder_attributes( $attributes ){
// here is the desired order
$order = array(
'pa_maker',
'pa_model-name',
'pa_man-lady',
'pa_model-case-ref',
'pa_case-serial'
);
$new_attributes = array();
// create new array based on order of $order array
foreach( $order as $key ){
if( isset( $attributes[$key] ) ){
// add to new attributes array
$new_attributes[$key] = $attributes[$key];
// remove from the attributes array
unset( $attributes[$key] );
}
}
// merge any leftover $attributes in at the end so we don't accidentally lose anything
$new_attributes = array_merge( $new_attributes, $attributes );
// set the new position keys
$i = 0;
foreach( $new_attributes as $key => $attribute ){
// update the position
$new_attributes[$key]['position'] = $i;
$i++;
}
return $new_attributes;
}
转到“属性”选项卡,将它们拖放到所需的顺序中。我不想这样做-这太耗时了-属性是在不同的时间创建的,因此现在在将大约20个属性应用到产品时,我们必须上下按正确的顺序添加它们,或者我们添加它们并按顺序重新排序拖动它们-这两种方法都非常耗时。如果属性在下拉列表中的顺序正确,将节省大量时间。谢谢具体的订单是什么?我将不得不考虑如何通过编程实现这一点。按字母顺序排列似乎是最可行的方法,虽然最好更新它们的存储顺序,这样您只需重新排序一次。我同意最好更新它们的存储顺序。转到“属性”选项卡,将它们拖放到所需的顺序。我不想这样做-太耗时了-属性是在不同的时间创建的因此,当我们将大约20个属性应用于一个产品时,我们必须在下拉菜单中上下按正确的顺序添加它们,或者我们添加它们,然后通过拖动它们来重新排序——这两种方法都非常耗时。如果属性在下拉列表中的顺序正确,将节省大量时间。谢谢具体的订单是什么?我将不得不考虑如何通过编程实现这一点。按字母顺序排序似乎是最可行的。这是非常有希望的,尽管最好更新它们的存储顺序,这样您只需重新排序一次。我同意最好更新它们的存储顺序。非常感谢,但我不希望对属性的条款进行重新排序,这很容易拖动。将属性添加到产品时,我希望在产品页面的下拉菜单中按特定顺序显示属性。属性的术语不是问题所在。请显示所需的结构。因为我认为没有人能告诉你你想要什么?非常感谢,但我不想重新排序属性的条款,这很容易拖动。将属性添加到产品时,我希望在产品页面的下拉菜单中按特定顺序显示属性。属性的术语不是问题所在。请显示结构
你想要的。因为我想没人能说出你想要什么?是的,这是唯一的办法。在手动创建属性时,position=>$i是我们想要的答案!是的,这是唯一的办法。在手动创建属性时,position=>$i是我们想要的答案!