PluginProbe
Whols – Wholesale Prices and B2B Store Solution for WooCommerce / trunk
Whols – Wholesale Prices and B2B Store Solution for WooCommerce vtrunk
2.4.12 2.4.11 trunk 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 55 releases
whols / includes / Admin / Custom_Columns.php

Custom_Columns.php in Whols – Wholesale Prices and B2B Store Solution for WooCommerce trunk, at includes/Admin/Custom_Columns.php

138 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Whols Post Columns.
4 *
5 * Filter Requested user post columns of Whols.
6 *
7 * @since 1.0.0
8 */
9
10 namespace Whols\Admin;
11
12 /**
13 * Post columns class.
14 */
15 class Custom_Columns {
16
17 /**
18 * Post columns constructor.
19 *
20 * @since 1.0.0
21 */
22 public function __construct() {
23 add_filter( 'manage_whols_user_request_posts_columns', array( $this, 'filter_posts_columns' ) );
24 add_action( 'manage_whols_user_request_posts_custom_column', array( $this, 'status_column_content' ), 10, 2 );
25
26 // taxonomy column
27 add_filter( 'manage_edit-whols_role_cat_columns', array( $this, 'register_role_category_columns' ) );
28 add_filter ( 'manage_whols_role_cat_custom_column', array( $this, 'render_role_categroy_column'), 10, 3 );
29
30 // Wholesale Price column into the Product list table
31 add_filter( 'manage_product_posts_columns', array( $this, 'add_wholesale_price_column' ), 50 );
32 add_action( 'manage_product_posts_custom_column', array( $this, 'wholesale_price_column_content' ), 10, 2 );
33 }
34
35 /**
36 * Filter posts columns.
37 *
38 * @since 1.0.0
39 *
40 * @return array Columns array.
41 */
42 public function filter_posts_columns( $columns ) {
43 $columns = array(
44 'cb' => $columns['cb'],
45 'title' => $columns['title'],
46 'shortcode' => esc_html__( 'Status', 'whols' ),
47 'date' => $columns['date'],
48 );
49
50 return $columns;
51 }
52
53 /**
54 * Status column content.
55 *
56 * @since 1.0.0
57 */
58 public function status_column_content( $column, $post_id ) {
59 $post_id = absint( $post_id );
60 $meta = get_post_meta( $post_id, 'whols_user_request_meta', true );
61
62 if( !empty($meta['status']) && $meta['status'] == 'approve' ){
63 printf(
64 /* translators: %1$s: Approved, %2$s: Approved, %3$s: Approved */
65 wp_kses_post(__( '%1$s Approved %2$s', 'whols' )),
66 '<span class="whols_approved">',
67 '</span>'
68 );
69 } else if( !empty($meta['status']) && $meta['status'] == 'reject' ){
70 printf(
71 /* translators: %1$s: Rejected, %2$s: Rejected, %3$s: Rejected */
72 wp_kses_post(__( '%1$s Rejected %2$s', 'whols' )),
73 '<span class="whols_rejected">',
74 '</span>'
75 );
76 } else {
77 printf(
78 /* translators: %1$s: Pending, %2$s: Pending, %3$s: Pending */
79 wp_kses_post(__( '%1$s Pending %2$s', 'whols' )),
80 '<span class="whols_pending">',
81 '</span>'
82 );
83 }
84 }
85
86 public function register_role_category_columns($columns){
87 // Remove Old count column
88 unset($columns['posts']);
89
90 // add count column title
91 $columns['count'] = esc_html__('Count', 'whols');
92
93 return $columns;
94 }
95
96 public function render_role_categroy_column( $deprecated, $column_name, $term_id ){
97 if ( $column_name == 'count' ) {
98 $role = get_term_field( 'slug', $term_id, '', 'display' );
99 $user_query = new \WP_User_Query( array( 'role' => $role ) );
100
101 echo '<a href="users.php?role='. esc_attr($role) .'">'. esc_html( count($user_query->get_results()) ) .'</a>';
102 }
103 }
104
105 // Add Wholesale Price column into the Product list table
106 public function add_wholesale_price_column( $columns ) {
107 // Insert wholesale price column after the price column
108 $columns = whols_insert_element_after_specific_array_key( $columns, 'price',
109 array(
110 'key' => 'wholesale_price',
111 'value' => __( 'Wholesale Price', 'whols' )
112 )
113 );
114
115 return $columns;
116 }
117
118 // Wholesale Price column content
119 public function wholesale_price_column_content( $column, $post_id ) {
120 if ( $column == 'wholesale_price' ) {
121 $post_id = absint( $post_id );
122
123 $pricing = new \Whols\Wholesale_Product_Pricing( $post_id );
124
125 if( $pricing->has_wholesale_pricing() ){
126 $price = $pricing->get_wholesale_price();
127
128 if( !is_array( $price ) ){
129 echo wp_kses_post(wc_price( $price ));
130 } elseif( $price['min'] && $price['max'] ){
131 // Display price range
132 echo wp_kses_post(wc_price( $price['min'] )) . ' - ' . wp_kses_post(wc_price( $price['max'] ));
133 }
134 }
135 }
136 }
137
138 } // Class