Empty row added after each attribute in add_to_cart widget
-
With the latest WooCommerce update, version 9.5.0 or version 9.5.1, you have changed the layout of the variation table in the add_to_cart widget.
The change is in this file
wp-content/plugins/woocommerce/templates/single-product/add-to-cart/variable.php
In the previous version, in the same <td> element where the variation dropdown was shown you were evaluating whether the Clear button needed to be added.
<td class="value">
<?php
wc_dropdown_variation_attribute_options(
array(
'options' => $options,
'attribute' => $attribute_name,
'product' => $product,
)
);
echo end( $attribute_keys ) === $attribute_name ? wp_kses_post( apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . esc_html__( 'Clear', 'woocommerce' ) . '</a>' ) ) : '';
?>
</td>Now you have moved that evaluation in a separate row of the table, inside its own <tr><td> element.
<tr>
<td colspan="2">
<?php
/**
* Filters the reset variation button.
*
* @since 2.5.0
*
* @param string $button The reset variation button HTML.
*/
echo end( $attribute_keys ) === $attribute_name ? wp_kses_post( apply_filters( 'woocommerce_reset_variations_link', '<button class="reset_variations" aria-label="' . esc_html__( 'Clear options', 'woocommerce' ) . '">' . esc_html__( 'Clear', 'woocommerce' ) . '</button>' ) ) : '';
?>
</td>
</tr>The effect of this change is that when the attribute being rendered is not the latest, an empty row is added to table below the attribute row.
You can see the after and the before in the attached images
After and Before I think you have broken the layout of a huge number of websites with this change.
What it is quite annoying is is that there isn’t even a filter or something to remove that empty table row.What would make much more sense is that the markup, the new <tr><td> is added only when
if end( $attribute_keys ) === $attribute_name
is true to ensure that the Clear button row is added only at the end for the latest attribute, instead of being added for each attribute.You should change that code with the following
<?php if ( end( $attribute_keys ) === $attribute_name ) : ?>
<tr>
<td colspan="2">
<?php
/**
* Filters the reset variation button.
*
* @since 2.5.0
*
* @param string $button The reset variation button HTML.
*/
echo wp_kses_post( apply_filters( 'woocommerce_reset_variations_link', '<button class="reset_variations" aria-label="' . esc_html__( 'Clear options', 'woocommerce' ) . '">' . esc_html__( 'Clear', 'woocommerce' ) . '</button>' ) );
?>
</td>
</tr>
<?php endif; ?>The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.