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_action( 'shop_order_project_edit_form_fields', array( __CLASS__, 'edit_is_available_field' ) );
|
||||||
|
|
||||||
// Add is available column
|
// Add is available column
|
||||||
add_filter( 'manage_edit-shop_order_project_columns', array( __CLASS__, 'add_is_available_column' ) );
|
add_filter( 'manage_edit-shop_order_project_columns', array( __CLASS__, 'update_table_headers' ) );
|
||||||
add_filter( 'manage_shop_order_project_custom_column', array( __CLASS__, 'add_is_available_column_content' ), 10, 3 );
|
add_filter( 'manage_shop_order_project_custom_column', array( __CLASS__, 'update_table_column_content' ), 10, 3 );
|
||||||
|
|
||||||
// Save is available field when creating and editing
|
// Save is available field when creating and editing
|
||||||
add_action( 'created_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
|
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
|
* @param array $columns Available order project table headers
|
||||||
*
|
*
|
||||||
* @return array Edited order project table headers
|
* @return array Edited order project table headers
|
||||||
*/
|
*/
|
||||||
public static function add_is_available_column($columns) {
|
public static function update_table_headers($columns) {
|
||||||
$columns['is_available'] = __( 'Is Available?', 'wiaas' );
|
$columns['wiaas_is_available'] = __( 'Is Available?', 'wiaas' );
|
||||||
|
|
||||||
|
$columns['wiaas_count'] = __('Count', 'wiaas');
|
||||||
|
|
||||||
|
unset($columns['posts']);
|
||||||
|
|
||||||
return $columns;
|
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 $columns Row content for order projects table
|
||||||
* @param string $column Current column header
|
* @param string $column Current column header
|
||||||
* @param int $id Order project id
|
* @param int $id Order project id
|
||||||
*
|
*
|
||||||
* @return string Edited row content with appended is available info
|
* @return string Edited row content with appended is available info
|
||||||
*/
|
*/
|
||||||
public static function add_is_available_column_content($columns, $column, $id) {
|
public static function update_table_column_content($columns, $column, $id) {
|
||||||
if ($column === 'is_available') {
|
if ($column === 'wiaas_is_available') {
|
||||||
$is_available = Wiaas_Order_Project::is_order_project_available($id);
|
$is_available = Wiaas_Order_Project::is_order_project_available($id);
|
||||||
$columns .= $is_available ? 'Yes' : 'No';
|
$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;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,11 +31,23 @@ class Wiaas_Order_Project {
|
|||||||
'show_admin_column' => true,
|
'show_admin_column' => true,
|
||||||
'query_var' => true,
|
'query_var' => true,
|
||||||
'rewrite' => array( 'slug' => 'shop_order_project' ),
|
'rewrite' => array( 'slug' => 'shop_order_project' ),
|
||||||
|
'update_count_callback' => array(__CLASS__, 'update_count_callback')
|
||||||
);
|
);
|
||||||
|
|
||||||
register_taxonomy( 'shop_order_project', array( 'shop_order' ), $args );
|
register_taxonomy( 'shop_order_project', array( 'shop_order' ), $args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback to handle counting of number of orders inside every project
|
||||||
|
* This does not work out of the box for orders since they are marked as private post type
|
||||||
|
*
|
||||||
|
* @param array $project_ids
|
||||||
|
*/
|
||||||
|
public static function update_count_callback($project_ids) {
|
||||||
|
// Update counts
|
||||||
|
_update_generic_term_count( $project_ids, get_taxonomy('shop_order_project') );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves available order projects
|
* Retrieves available order projects
|
||||||
* @return array List of available order projects
|
* @return array List of available order projects
|
||||||
|
|||||||
Reference in New Issue
Block a user