admin管理员组文章数量:1416651
How do I either replace or completely remove a column in the Woocommerce Orders list in admin?
I know that there's possible to just uncheck the "Shipping address" column from the "Screen Options" and add another custom column and name it "Shipping address" too. But idealy I would like to just have one "Shipping address" column option and just be able to change what's in that column.
I have tried to first just remove the "Shipping address" column but isn't succeeding with that either:
function new_orders_columns($columns)
{
unset($columns['shippging_address']);
return $columns;
}
function after_woo()
{
add_filter('manage_shop_order_posts_columns', 'new_orders_columns', 10, 1);
}
add_action('plugins_loaded', 'after_woo');
It just won't be removed. I have tried to change the priority and init/loaded hooks. But nothing works.
Any help here?
How do I either replace or completely remove a column in the Woocommerce Orders list in admin?
I know that there's possible to just uncheck the "Shipping address" column from the "Screen Options" and add another custom column and name it "Shipping address" too. But idealy I would like to just have one "Shipping address" column option and just be able to change what's in that column.
I have tried to first just remove the "Shipping address" column but isn't succeeding with that either:
function new_orders_columns($columns)
{
unset($columns['shippging_address']);
return $columns;
}
function after_woo()
{
add_filter('manage_shop_order_posts_columns', 'new_orders_columns', 10, 1);
}
add_action('plugins_loaded', 'after_woo');
It just won't be removed. I have tried to change the priority and init/loaded hooks. But nothing works.
Any help here?
Share Improve this question edited Aug 9, 2019 at 10:18 Peter Westerlund asked May 18, 2019 at 19:55 Peter WesterlundPeter Westerlund 1,0775 gold badges14 silver badges31 bronze badges 01 Answer
Reset to default 4The correct filter hook to be used is manage_edit-shop_order_columns
.
1) To remove shipping_address
column:
add_filter( 'manage_edit-shop_order_columns', 'remove_specific_orders_column' );
function remove_specific_orders_column( $columns ){
unset( $columns['shipping_address'] );
return $new_columns;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
2) Replace the content of shipping_address
column:
Here is an example that will replace the column "Shipping address" content from Admin Orders list:
add_filter( 'manage_edit-shop_order_columns', 'customizing_orders_columns' );
function customizing_orders_columns( $columns ){
$new_columns = [];
foreach ( $columns as $key => $column ) {
if( $key === 'shipping_address' ) {
$new_columns['shipping_addr_repl'] = $column;
} else {
$new_columns[$key] = $column;
}
}
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'set_custom_shipping_address_content_replacement' );
function set_custom_shipping_address_content_replacement( $column ) {
global $the_order, $post;
if ( 'shipping_addr_repl' === $column ) {
// YOUR REPLACEMENT CODE (Fake example below)
echo $the_order->get_shipping_city();
}
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
The original displayed content code for this column is:
$address = $the_order->get_formatted_shipping_address();
if ( $address ) {
echo '<a target="_blank" href="' . esc_url( $the_order->get_shipping_address_map_url() ) . '">' . esc_html( preg_replace( '#<br\s*/?>#i', ', ', $address ) ) . '</a>';
if ( $the_order->get_shipping_method() ) {
/* translators: %s: shipping method */
echo '<span class="description">' . sprintf( __( 'via %s', 'woocommerce' ), esc_html( $the_order->get_shipping_method() ) ) . '</span>'; // WPCS: XSS ok.
}
} else {
echo '–';
}
本文标签: phpReplace existing content from specific WooCommerce admin orders list column
版权声明:本文标题:php - Replace existing content from specific WooCommerce admin orders list column 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745256071a2650109.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论