我正在嘗試使用以下代碼從管理員的訂單頁面中洗掉所有默認批量操作:
add_filter( 'bulk_actions-edit-shop_order', 'remove_order_statuses_bulk' );
function remove_order_statuses_bulk ( $bulk_actions ) {
error_log( print_r( $bulk_actions, true ) );
$unwanted_actions = array( "mark_processing", "mark_pending", "mark_on-hold", "mark_completed", "mark_cancelled", "mark_refunded", "mark_failed" );
foreach ( $unwanted_actions as $action ) {
if ( isset( $bulk_actions[$action] ) ) {
unset( $bulk_actions[$action] );
}
}
return $bulk_actions;
}
error_log 顯示了僅包含"edit"
,"trash"
和的陣列"mark_custom-status"
(這是我使用同一個鉤子創建的狀態)。所以陣列已經是空的了。
問題是帶有批量操作的選單wp-admin/edit.php?post_type=shop_order
仍然顯示已洗掉的條目。
我目前沒有快取插件。這可能是什么原因造成的?
uj5u.com熱心網友回復:
由于您沒有設定優先級,因此您的函式被呼叫得太早。
改變你的優先級,add_filter
它的作業原理。
add_filter( 'bulk_actions-edit-shop_order', 'remove_order_statuses_bulk', 40, 1 );
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/470889.html