When handling variations, priority from top to bottom - disabled variations still taking into consideration allow you to exclude certain combinations when using 'all' for variations with lower priority. Message displayed if a variation is unavailable.
@coenjacobs please review
This commit is contained in:
parent
eef86ab5eb
commit
ece95e25ce
|
@ -386,6 +386,11 @@
|
|||
$variation_form.find('.variations_button').hide();
|
||||
}
|
||||
|
||||
if ( ! variation.variation_is_visible ) {
|
||||
$variation_form.find('.variations_button').hide();
|
||||
$variation_form.find('.single_variation').html( '<p>' + wc_add_to_cart_variation_params.i18n_unavailable_text + '</p>' );
|
||||
}
|
||||
|
||||
if ( variation.min_qty )
|
||||
$single_variation_wrap.find('input[name=quantity]').attr( 'min', variation.min_qty ).val( variation.min_qty );
|
||||
else
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -141,6 +141,7 @@ class WC_Frontend_Scripts {
|
|||
|
||||
wp_localize_script( 'wc-add-to-cart-variation', 'wc_add_to_cart_variation_params', apply_filters( 'wc_add_to_cart_variation_params', array(
|
||||
'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce' ),
|
||||
'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ),
|
||||
) ) );
|
||||
|
||||
wp_localize_script( 'wc-country-select', 'wc_country_select_params', apply_filters( 'wc_country_select_params', array(
|
||||
|
|
|
@ -286,16 +286,19 @@ class WC_Product_Variable extends WC_Product {
|
|||
|
||||
foreach ( $this->get_children() as $child_id ) {
|
||||
|
||||
if ( get_post_status( $child_id ) != 'publish' )
|
||||
continue; // Disabled
|
||||
$variation = $this->get_child( $child_id );
|
||||
|
||||
$child = $this->get_child( $child_id );
|
||||
if ( ! empty( $variation->variation_id ) ) {
|
||||
|
||||
$child_variation_attributes = $child->get_variation_attributes();
|
||||
if ( ! $variation->variation_is_visible() )
|
||||
continue; // Disabled or hidden
|
||||
|
||||
foreach ( $child_variation_attributes as $name => $value )
|
||||
if ( $name == $attribute_field_name )
|
||||
$values[] = sanitize_title( $value );
|
||||
$child_variation_attributes = $variation->get_variation_attributes();
|
||||
|
||||
foreach ( $child_variation_attributes as $name => $value )
|
||||
if ( $name == $attribute_field_name )
|
||||
$values[] = sanitize_title( $value );
|
||||
}
|
||||
}
|
||||
|
||||
// empty value indicates that all options for given attribute are available
|
||||
|
@ -361,10 +364,6 @@ class WC_Product_Variable extends WC_Product {
|
|||
$variation = $this->get_child( $child_id );
|
||||
|
||||
if ( ! empty( $variation->variation_id ) ) {
|
||||
|
||||
if ( ! $variation->variation_is_visible() )
|
||||
continue; // Disabled or hidden
|
||||
|
||||
$variation_attributes = $variation->get_variation_attributes();
|
||||
$availability = $variation->get_availability();
|
||||
$availability_html = empty( $availability['availability'] ) ? '' : apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">'. wp_kses_post( $availability['availability'] ).'</p>', wp_kses_post( $availability['availability'] ) );
|
||||
|
@ -385,24 +384,25 @@ class WC_Product_Variable extends WC_Product {
|
|||
}
|
||||
|
||||
$available_variations[] = apply_filters( 'woocommerce_available_variation', array(
|
||||
'variation_id' => $child_id,
|
||||
'attributes' => $variation_attributes,
|
||||
'image_src' => $image,
|
||||
'image_link' => $image_link,
|
||||
'image_title' => $image_title,
|
||||
'image_alt' => $image_alt,
|
||||
'price_html' => $this->min_variation_price != $this->max_variation_price ? '<span class="price">' . $variation->get_price_html() . '</span>' : '',
|
||||
'availability_html' => $availability_html,
|
||||
'sku' => $variation->get_sku(),
|
||||
'weight' => $variation->get_weight() . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) ),
|
||||
'dimensions' => $variation->get_dimensions(),
|
||||
'min_qty' => 1,
|
||||
'max_qty' => $this->backorders_allowed() ? '' : $variation->stock,
|
||||
'backorders_allowed' => $this->backorders_allowed(),
|
||||
'is_in_stock' => $variation->is_in_stock(),
|
||||
'is_downloadable' => $variation->is_downloadable() ,
|
||||
'is_virtual' => $variation->is_virtual(),
|
||||
'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no',
|
||||
'variation_id' => $child_id,
|
||||
'variation_is_visible' => $variation->variation_is_visible(),
|
||||
'attributes' => $variation_attributes,
|
||||
'image_src' => $image,
|
||||
'image_link' => $image_link,
|
||||
'image_title' => $image_title,
|
||||
'image_alt' => $image_alt,
|
||||
'price_html' => $this->min_variation_price != $this->max_variation_price ? '<span class="price">' . $variation->get_price_html() . '</span>' : '',
|
||||
'availability_html' => $availability_html,
|
||||
'sku' => $variation->get_sku(),
|
||||
'weight' => $variation->get_weight() . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) ),
|
||||
'dimensions' => $variation->get_dimensions(),
|
||||
'min_qty' => 1,
|
||||
'max_qty' => $this->backorders_allowed() ? '' : $variation->stock,
|
||||
'backorders_allowed' => $this->backorders_allowed(),
|
||||
'is_in_stock' => $variation->is_in_stock(),
|
||||
'is_downloadable' => $variation->is_downloadable() ,
|
||||
'is_virtual' => $variation->is_virtual(),
|
||||
'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no',
|
||||
), $this, $variation );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ class WC_Product_Variation extends WC_Product {
|
|||
public function variation_is_visible() {
|
||||
$visible = true;
|
||||
|
||||
// Published
|
||||
// Published == enabled checkbox
|
||||
if ( get_post_status( $this->variation_id ) != 'publish' )
|
||||
$visible = false;
|
||||
|
||||
|
@ -236,6 +236,24 @@ class WC_Product_Variation extends WC_Product {
|
|||
return apply_filters( 'woocommerce_variation_is_visible', $visible, $this->variation_id, $this->id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false if the product cannot be bought.
|
||||
*
|
||||
* @access public
|
||||
* @return cool
|
||||
*/
|
||||
public function is_purchasable() {
|
||||
|
||||
// Published == enabled checkbox
|
||||
if ( get_post_status( $this->variation_id ) != 'publish' )
|
||||
$purchasable = false;
|
||||
|
||||
else
|
||||
$purchasable = parent::is_purchasable();
|
||||
|
||||
return $purchasable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the variations parent is visible.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue