Fix broken counting of orders inside order project
This commit is contained in:
@@ -13,8 +13,8 @@ class Wiaas_Admin_Order_Projects {
|
||||
add_action( 'shop_order_project_edit_form_fields', array( __CLASS__, 'edit_is_available_field' ) );
|
||||
|
||||
// Add is available column
|
||||
add_filter( 'manage_edit-shop_order_project_columns', array( __CLASS__, 'add_is_available_column' ) );
|
||||
add_filter( 'manage_shop_order_project_custom_column', array( __CLASS__, 'add_is_available_column_content' ), 10, 3 );
|
||||
add_filter( 'manage_edit-shop_order_project_columns', array( __CLASS__, 'update_table_headers' ) );
|
||||
add_filter( 'manage_shop_order_project_custom_column', array( __CLASS__, 'update_table_column_content' ), 10, 3 );
|
||||
|
||||
// Save is available field when creating and editing
|
||||
add_action( 'created_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
|
||||
@@ -88,30 +88,48 @@ class Wiaas_Admin_Order_Projects {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add is_available column header to available order projects table headers
|
||||
* Update table headers for order projects
|
||||
* Will add `is available` and `wiaas count` columns and remove default count column
|
||||
*
|
||||
* @param array $columns Available order project table headers
|
||||
*
|
||||
* @return array Edited order project table headers
|
||||
*/
|
||||
public static function add_is_available_column($columns) {
|
||||
$columns['is_available'] = __( 'Is Available?', 'wiaas' );
|
||||
public static function update_table_headers($columns) {
|
||||
$columns['wiaas_is_available'] = __( 'Is Available?', 'wiaas' );
|
||||
|
||||
$columns['wiaas_count'] = __('Count', 'wiaas');
|
||||
|
||||
unset($columns['posts']);
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render content for order project is available table column
|
||||
* Render content for order project table column
|
||||
* Will add content for `is available` and `wiaas count` columns
|
||||
*
|
||||
* @param string $columns Row content for order projects table
|
||||
* @param string $column Current column header
|
||||
* @param int $id Order project id
|
||||
*
|
||||
* @return string Edited row content with appended is available info
|
||||
*/
|
||||
public static function add_is_available_column_content($columns, $column, $id) {
|
||||
if ($column === 'is_available') {
|
||||
public static function update_table_column_content($columns, $column, $id) {
|
||||
if ($column === 'wiaas_is_available') {
|
||||
$is_available = Wiaas_Order_Project::is_order_project_available($id);
|
||||
$columns .= $is_available ? 'Yes' : 'No';
|
||||
}
|
||||
|
||||
if ($column === 'wiaas_count') {
|
||||
$term = get_term($id, 'shop_order_project');
|
||||
$args = array(
|
||||
'shop_order_project' => $term->slug,
|
||||
'post_type' => 'shop_order'
|
||||
);
|
||||
$columns .= "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$term->count</a>";
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user