我想在woocommerce產品管理部分的下拉列表中以特定順序顯示「屬性」。屬性沒有以正確的順序輸入。現在重做它已經太晚了,所以我想在下拉菜單中列出它們應該顯示的內容。輸入數據的人在列表中上下滾動太耗時。如果他們已經按照正確的順序,那會更快。我已經看到了如何迫使他們在前端而不是在管理部分在一個特定的順序顯示 - 感謝我想在woocommerce產品管理部分的下拉列表中以特定順序顯示「屬性」
1
A
回答
1
+0
非常感謝,但我不想重新排序容易(拖動)的屬性的「條款」。將產品添加到產品時,我想在產品頁面的下拉菜單中按特定順序顯示屬性。屬性的條款不是問題。 – ESP5466
+1
讓我看看你想要的結構。因爲我認爲沒有人能告訴你想要什麼? –
1
運行該代碼一次,然後將其刪除。因此將其加載到插件中,激活插件,然後停用。我想過自動停用或創建一次運行,但我會讓你處理它。如果代碼第一次不正確,那實際上會很麻煩。
也許你可以修改第二個功能,也可以在save_post
上運行,或者在店鋪經理未來按錯誤順序添加屬性時更換attributes_cmp()
。實際上,是一個名爲update_post_metadata
的過濾器,可以讓您在每次更新帖子和保存元數據時始終如一地應用此選項。
警告備份您的數據庫!此代碼具有破壞性,並且將永久更改您的數據庫,並且而不是已被測試,除了看到新的排序功能在演示陣列上工作之外。使用風險自負。
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;
}
相關問題
- 1. 特定WooCommerce產品類別的隱藏屬性下拉列表
- 2. Woocommerce - 分組的產品 - 顯示順序
- 3. 我只想創造一個類別,以顯示產品中的特定屬性
- 4. Woocommerce:按字母順序顯示產品
- 5. 顯示特定產品類別的條款或產品屬性(woocommerce)
- 6. 列出按字母順序排列的產品屬性(Woocommerce)
- 7. 獲取特定woocommerce產品的屬性列表
- 8. Woocommerce產品屬性條件顯示
- 9. Woocommerce:按屬性顯示產品過濾
- 10. 自定義的產品屬性不管理目錄部分Magento的顯示2.1
- 11. Woocommerce如何按字母順序顯示產品列表?
- 12. woocommerce顯示特定頁面的產品
- 13. 下拉列表誰加載產品woocommerce
- 14. woocommerce:產品變量下拉不顯示在我的主題
- 15. WooCommerce:在管理產品列表中移動列位置
- 16. Magento:如何在產品列表頁面上顯示下拉屬性
- 17. Woocommerce在特定類別的邊欄中顯示產品
- 18. Wordpress無法加載產品中的Woocommerce屬性部分
- 19. 按順序顯示ASP下拉列表
- 20. 需要顯示產品頁面中的當前產品屬性woocommerce
- 21. wooCommerce顯示在單個產品頁面上的屬性描述
- 22. Woocommerce - 產品屬性查詢
- 23. Woocommerce list產品屬性
- 24. Woocommerce產品差異屬性
- 25. 是否可以在前端的分組產品下顯示相關產品的自定義屬性? (Magento)
- 26. WordPress Woocommerce:按隨機順序顯示最近的產品
- 27. WooCommerce產品 - 顯示產品對象
- 28. Woocommerce產品頁面未顯示產品
- 29. 如何按照我想要的順序排列woocommerce產品類別?
- 30. 如何顯示在WordPress woocommerce特定頁面上的產品呢?
轉到屬性選項卡並將其拖放到所需的順序。 – helgatheviking
我不想這麼做 - 它太費時 - 屬性已經在不同的時間創建,所以現在當將大約20個屬性應用到一個產品時,我們必須在下拉菜單中上下移動以將它們添加到正確的訂單或我們添加它們,我們通過拖動它們來重新排序 - 兩種方法都非常耗時。如果屬性在下拉列表中按正確順序排列,可以節省大量時間。謝謝 – ESP5466
特定的順序是什麼?我將不得不考慮如何以編程方式執行此操作。按字母順序排列似乎是最可行的。 – helgatheviking