Tweak template logic to load variations when needed
This commit is contained in:
parent
65f19d5ca7
commit
eaed944048
|
@ -879,9 +879,12 @@ if ( ! function_exists( 'woocommerce_variable_add_to_cart' ) ) {
|
|||
// Enqueue variation scripts
|
||||
wp_enqueue_script( 'wc-add-to-cart-variation' );
|
||||
|
||||
// Get Available variations?
|
||||
$get_variations = sizeof( $product->get_children() ) <= apply_filters( 'woocommerce_max_variations', 20 );
|
||||
|
||||
// Load the template
|
||||
wc_get_template( 'single-product/add-to-cart/variable.php', array(
|
||||
'available_variations' => sizeof( $product->get_children() ) <= apply_filters( 'woocommerce_max_variations', 20 ) ? $product->get_available_variations() : false,
|
||||
'available_variations' => $get_variations ? $product->get_available_variations() : false,
|
||||
'attributes' => $product->get_variation_attributes(),
|
||||
'selected_attributes' => $product->get_variation_default_attributes()
|
||||
) );
|
||||
|
|
|
@ -20,7 +20,7 @@ global $product, $post;
|
|||
|
||||
<?php do_action( 'woocommerce_before_variations_form' ); ?>
|
||||
|
||||
<?php if ( 1 || ! empty( $available_variations ) ) : ?>
|
||||
<?php if ( ! empty( $available_variations ) || false === $available_variations ) : ?>
|
||||
<table class="variations" cellspacing="0">
|
||||
<tbody>
|
||||
<?php $loop = 0; foreach ( $attributes as $name => $options ) : $loop++; ?>
|
||||
|
|
Loading…
Reference in New Issue