Merge pull request #7021 from bryceadams/patch-7019

Add filter 'woocommerce_grouped_children_args'
This commit is contained in:
Mike Jolley 2014-12-30 14:47:39 +00:00
commit d09353c689
1 changed files with 17 additions and 5 deletions

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* Grouped products cannot be purchased - they are wrappers for other products. * Grouped products cannot be purchased - they are wrappers for other products.
* *
* @class WC_Product_Grouped * @class WC_Product_Grouped
* @version 2.0.0 * @version 2.3.0
* @package WooCommerce/Classes/Products * @package WooCommerce/Classes/Products
* @category Class * @category Class
* @author WooThemes * @author WooThemes
@ -62,7 +62,7 @@ class WC_Product_Grouped extends WC_Product {
$this->total_stock = $this->stock; $this->total_stock = $this->stock;
if ( sizeof( $this->get_children() ) > 0 ) { if ( sizeof( $this->get_children() ) > 0 ) {
foreach ($this->get_children() as $child_id) { foreach ( $this->get_children() as $child_id ) {
$stock = get_post_meta( $child_id, '_stock', true ); $stock = get_post_meta( $child_id, '_stock', true );
if ( $stock != '' ) { if ( $stock != '' ) {
@ -91,7 +91,17 @@ class WC_Product_Grouped extends WC_Product {
if ( empty( $this->children ) ) { if ( empty( $this->children ) ) {
$this->children = get_posts( 'post_parent=' . $this->id . '&post_type=product&orderby=menu_order&order=ASC&fields=ids&post_status=publish&numberposts=-1' ); $args = apply_filters( 'woocommerce_grouped_children_args', array(
'post_parent' => $this->id,
'post_type' => 'product',
'orderby' => 'menu_order',
'order' => 'ASC',
'fields' => 'ids',
'post_status' => 'publish',
'numberposts' => -1,
) );
$this->children = get_posts( $args );
set_transient( $transient_name, $this->children, YEAR_IN_SECONDS ); set_transient( $transient_name, $this->children, YEAR_IN_SECONDS );
} }
@ -134,14 +144,16 @@ class WC_Product_Grouped extends WC_Product {
foreach ( $this->get_children() as $child_id ) { foreach ( $this->get_children() as $child_id ) {
$sale_price = get_post_meta( $child_id, '_sale_price', true ); $sale_price = get_post_meta( $child_id, '_sale_price', true );
if ( $sale_price !== "" && $sale_price >= 0 ) if ( $sale_price !== "" && $sale_price >= 0 ) {
return true; return true;
}
} }
} else { } else {
if ( $this->sale_price && $this->sale_price == $this->price ) if ( $this->sale_price && $this->sale_price == $this->price ) {
return true; return true;
}
} }
return false; return false;