prepare_items(); ?>
'product', 'plural' => 'products', 'ajax' => false ) ); } /** * Prepare the items for the table to process * * @return Void */ public function prepare_items() { global $wpdb; $this->process_bulk_action(); $columns = $this->get_columns(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $data = $this->table_data(); $currentPage = $this->get_pagenum(); $search = empty( $_REQUEST['s'] ) ? false : esc_sql( $_REQUEST['s'] ); $prtltArg = array( 'post_type' => 'product', 'post_status' => array('publish', 'draft'), 'posts_per_page' => -1, ); $prtltArg['meta_query'][] = array( 'key' => 'product_status', 'value' => 1, 'compare' => '==', ); if( $search ){ $prtltArg['s'] = $search; } $productCnt = get_posts( $prtltArg ); $total_items = count( $productCnt ) ? count( $productCnt ) : 0; $this->set_pagination_args( array( 'total_items' => $total_items, 'per_page' => $this->post_per_page, 'total_pages' => ceil( $total_items / $this->post_per_page ) // use ceil to round up ) ); $this->_column_headers = array($columns, $hidden ,$sortable); $this->items = $data; } /** * Override the parent columns method. Defines the columns to use in your listing table * * @return Array */ public function get_columns() { $columns = array( 'cb' => '', 'thumbnail' => __( 'Image', 'bytes_product_frontend' ), 'name' => __( 'Product Name ', 'bytes_product_frontend' ), 'sku' => __( 'SKU ', 'bytes_product_frontend' ), 'price' => __( 'Price ', 'bytes_product_frontend' ), 'author'=> __( 'Author ', 'bytes_product_frontend' ), 'status'=> __( 'Status ', 'bytes_product_frontend' ), ); return $columns; } /** * Define check box for bulk action (each row) * @param $item * @return checkbox */ public function column_cb($item){ return sprintf( '', $this->_args['singular'], $item['cb'] ); } /** * Define which columns are hidden * * @return Array */ public function get_hidden_columns() { return array('form_id'); } /** * Define the sortable columns * * @return Array */ public function get_sortable_columns() { $sortableFields = array( 'name' => array( 'name', true ), 'price' => array( 'price', true ), ); return $sortableFields; } /** * Define bulk action * @return Array */ public function get_bulk_actions() { return array( 'delete' => __( 'Move to Trash', 'bytes_product_frontend' ) ); } /** * Get the table data * * @return Array */ private function table_data() { $data = array(); global $wpdb; $paged = $this->get_pagenum(); $search = empty( $_REQUEST[ 's' ] ) ? false : esc_sql( $_REQUEST[ 's' ] ); $orderby = isset( $_GET[ 'orderby' ] ) ? esc_sql( $_GET[ 'orderby' ] ) : ""; $order = isset( $_GET[ 'order' ] ) ? esc_sql( $_GET[ 'order' ] ) : ""; $author = ""; $args = array( 'post_type' => 'product', 'post_status' => array( 'publish', 'draft' ), 'posts_per_page' => $this->post_per_page, 'paged' => $paged, ); $args['meta_query'][] = array( 'key' => 'product_status', 'value' => 1, 'compare' => '==', ); $usr_role = isset( $_GET[ 'apffw_user_roles' ] ) ? esc_sql( $_GET[ 'apffw_user_roles' ] ) : ""; $usr_id = isset( $_GET[ 'apffw_user_id' ] ) && $_GET[ 'apffw_user_id' ] != -1 ? esc_sql( $_GET[ 'apffw_user_id' ] ) : ""; if( !$usr_id && $usr_role ){ $users = get_users( array( 'role' => $usr_role, // Specify the role you want to query 'fields' => 'ID' // Retrieve only user IDs ) ); $args[ 'author__in' ] = $users; } elseif($usr_role){ $users = ($usr_id > 0) ? $usr_id : ""; $args[ 'author' ] = $users; } else{ $users = ($usr_id > 0) ? $usr_id : ""; $args[ 'author' ] = $users; } // Search if( $search ) { $args[ 's' ] = $search; } // Sorting if( ! empty( $orderby ) && ! empty( $order ) ) { if( $orderby == 'price'){ $args[ 'orderby' ] = 'meta_value_num'; $args[ 'meta_key' ] = '_price'; $args[ 'order' ] = $order; } else{ $args[ 'order' ] = $order; $args[ 'orderby' ] = $orderby; } } $the_query = new WP_Query( $args ); while ( $the_query->have_posts() ) : $the_query->the_post(); $prodId = get_the_id(); $product = wc_get_product( $prodId ); $title = esc_html__( sanitize_title( $product->get_name() ), 'bytes_product_frontend'); $link = "%s"; $placeholder = wc_placeholder_img_src(); $image = wp_get_attachment_image_src( get_post_thumbnail_id( $prodId ) ); $prodImg = "