diff --git a/includes/admin/list-tables/class-wc-admin-list-table-products.php b/includes/admin/list-tables/class-wc-admin-list-table-products.php index 646d91e868d..a0091c32f77 100644 --- a/includes/admin/list-tables/class-wc-admin-list-table-products.php +++ b/includes/admin/list-tables/class-wc-admin-list-table-products.php @@ -39,6 +39,7 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table { add_filter( 'query_vars', array( $this, 'add_custom_query_var' ) ); add_filter( 'views_edit-product', array( $this, 'product_views' ) ); add_filter( 'get_search_query', array( $this, 'search_label' ) ); + add_filter( 'posts_clauses', array( $this, 'add_variation_parents_for_shipping_class' ), 10, 2 ); } /** @@ -497,4 +498,26 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table { return wc_clean( wp_unslash( $_GET['s'] ) ); // WPCS: input var ok, sanitization ok. } + + /** + * Modifies post query so that it includes parent products whose variations have particular shipping class assigned. + * + * @param array $pieces Array of SELECT statement pieces (from, where, etc). + * @param WP_Query $wp_query WP_Query instance. + * @return array Array of products, including parents of variations. + */ + public function add_variation_parents_for_shipping_class( $pieces, $wp_query ) { + global $wpdb; + if ( isset( $_GET['product_shipping_class'] ) && '0' !== $_GET['product_shipping_class'] ) { // WPCS: input var ok. + $replaced_where = str_replace( ".post_type = 'product'", ".post_type = 'product_variation'", $pieces['where'] ); + $pieces['where'] .= " OR {$wpdb->posts}.ID in ( + SELECT {$wpdb->posts}.post_parent FROM + wp_posts LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) + WHERE 1=1 $replaced_where + )"; + return $pieces; + } + return $pieces; + } + } diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index 3b93e5027c6..dc9ac535c9d 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -209,7 +209,6 @@ class WC_Shipping { /** * Returns all registered shipping methods for usage. * - * @access public * @return array */ public function get_shipping_methods() { @@ -222,7 +221,6 @@ class WC_Shipping { /** * Get an array of shipping classes. * - * @access public * @return array */ public function get_shipping_classes() {