I am trying override a function from class WC_Admin_Post_Types and tried something like this:
plugins/customization/wc_admin_post_types_new.php
class WC_Admin_Post_Types_new {
public function __construct() {
add_filter( 'views_edit-product', array( $this, 'product_sorting_link_new' ) );
}
public function product_sorting_link_new( $views ) {
global $post_type, $wp_query;
if ( ! current_user_can('edit_others_pages') ) {
return $views;
}
$class = ( isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) ? 'current' : '';
$query_string = remove_query_arg(array( 'orderby', 'order' ));
$query_string = add_query_arg( 'orderby', urlencode('menu_order title'), $query_string );
$query_string = add_query_arg( 'order', urlencode('ASC'), $query_string );
$views['byorder'] = '<a href="' . esc_url( $query_string ) . '" class="' . esc_attr( $class ) . '">' . __( 'Sort Courses', 'woocommerce' ) . '</a>';
return $views;
}
}
new WC_Admin_Post_Types_new();
Original class looks like this
plugins/woocommerce/includes/admin/class-wc-admin-post-types.php
class WC_Admin_Post_Types {
public function __construct() {
add_filter( 'views_edit-product', array( $this, 'product_sorting_link' ) );
}
public function product_sorting_link( $views ) {
global $post_type, $wp_query;
if ( ! current_user_can('edit_others_pages') ) {
return $views;
}
$class = ( isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) ? 'current' : '';
$query_string = remove_query_arg(array( 'orderby', 'order' ));
$query_string = add_query_arg( 'orderby', urlencode('menu_order title'), $query_string );
$query_string = add_query_arg( 'order', urlencode('ASC'), $query_string );
$views['byorder'] = '<a href="' . esc_url( $query_string ) . '" class="' . esc_attr( $class ) . '">' . __( 'Sort Products', 'woocommerce' ) . '</a>';
return $views;
}
}
new WC_Admin_Post_Types();
I am trying to change
$views['byorder'] = '<a href="' . esc_url( $query_string ) . '" class="' . esc_attr( $class ) . '">' . __( 'Sort Products', 'woocommerce' ) . '</a>';
with
$views['byorder'] = '<a href="' . esc_url( $query_string ) . '" class="' . esc_attr( $class ) . '">' . __( 'Sort Courses', 'woocommerce' ) . '</a>';
Tried adding
remove_filter( 'views_edit-product', array( 'WC_Admin_Post_Types', 'product_sorting_link_new' ) );
in the __construct
and outside the class, but always returned false.
So how can I remove this filter and replace Sort Products
with Sort Courses
without editing or without using .pot. Need to know because there will be more altering on different classes from woocommerce.
For this I have written a little function:
However I find this method to be quite clean.
Found a temporary fix, but still not able to do it by the book like remove the filter or action. I added this function outside the class, before the class and it worked overriding.