WC_Admin_List_Table_Products::add_variation_parents_for_shipping_class
Modifies post query so that it includes parent products whose variations have particular shipping class assigned.
Method of the class: WC_Admin_List_Table_Products{}
No Hooks.
Returns
Array. Array of products, including parents of variations.
Usage
$WC_Admin_List_Table_Products = new WC_Admin_List_Table_Products(); $WC_Admin_List_Table_Products->add_variation_parents_for_shipping_class( $pieces, $wp_query );
- $pieces(array) (required)
- Array of SELECT statement pieces (from, where, etc).
- $wp_query(WP_Query) (required)
- WP_Query instance.
WC_Admin_List_Table_Products::add_variation_parents_for_shipping_class() WC Admin List Table Products::add variation parents for shipping class code WC 10.3.3
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
{$wpdb->posts} LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)
WHERE 1=1 $replaced_where
)";
return $pieces;
}
return $pieces;
}