Merge pull request #21278 from woocommerce/fix/20989

Updated shipping class count and posts query to account for variations correctly.
This commit is contained in:
Claudiu Lodromanean 2018-09-10 09:02:31 -07:00 committed by GitHub
commit f7028154a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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() {