Я отредактировал шаблон WooCommerce, чтобы вывод меток вариантов был в том же значении tr, а значения вариантов были соответственно в одном и том же значении.
Пока все работает нормально, но я хочу изменить значение tr после третий тд-л oop.
Это мой php:
<table class="variations" cellspacing="0">
<tbody>
<?php $labels = $values = ''; ?>
<?php $loop = 0; foreach ( $attributes as $attribute_name => $options ) : $loop++; ?>
<?php
$swatches = theme_has_swatches( $product->get_id(), $attribute_name, $options, $available_variations, $swatches_use_variation_images);
$active_variations = theme_get_active_variations( $attribute_name, $available_variations );
?>
<?php ob_start(); ?>
<td class="label" style="padding-right: 15px;min-width: 175px;"><label for="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
<?php $labels .= ob_get_contents(); ob_end_clean(); ?>
<?php ob_start(); ?>
<td class="value <?php if ( ! empty( $swatches ) ): ?>with-swatches<?php endif; ?>" style="padding-right: 15px;min-width: 175px;">
<?php if ( ! empty( $swatches ) ): ?>
<div class="swatches-select swatches-on-single" data-id="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>">
<?php
if ( is_array( $options ) ) {
if ( isset( $_REQUEST[ 'attribute_' . $attribute_name ] ) ) {
$selected_value = $_REQUEST[ 'attribute_' . $attribute_name ];
} elseif ( isset( $selected_attributes[ $attribute_name ] ) ) {
$selected_value = $selected_attributes[ $attribute_name ];
} else {
$selected_value = '';
}
// Get terms if this is a taxonomy - ordered
if ( taxonomy_exists( $attribute_name ) ) {
$terms = wc_get_product_terms( $product->get_id(), $attribute_name, array( 'fields' => 'all' ) );
$swatch_size = theme_wc_get_attribute_term( $attribute_name, 'swatch_size' );
$_i = 0;
$options_fliped = array_flip( $options );
foreach ( $terms as $term ) {
if ( ! in_array( $term->slug, $options ) ) {
continue;
}
$key = $options_fliped[$term->slug];
$style = '';
$class = 'theme-swatch swatch-on-single ';
$class .= ' swatch-size-' . $swatch_size;
if ( $selected_value == $term->slug ) {
$class .= ' active-swatch';
}
echo '<div class="' . esc_attr( $class ) . '" data-value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $term->slug ), false ) . ' style="' . esc_attr( $style ) .'">' . apply_filters( 'woocommerce_variation_option_name', $term->name ) . '</div>';
$_i++;
}
} else {
foreach ( $options as $option ) {
$class = '';
if ( $selected_value == $option ) {
$class .= ' active-swatch';
}
if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && $active_variations ) {
if ( in_array( $term->slug, $active_variations ) ) {
$class .= ' swatch-enabled';
} else {
$class .= ' swatch-disabled';
}
}
echo '<div class="' . esc_attr( $class ) . '" data-value="' . esc_attr( sanitize_title( $option ) ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $option ), false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</div>';
}
}
}
?>
</div>
<?php endif; ?>
<?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>
<?php $values .= ob_get_contents(); ob_end_clean(); ?>
<?php endforeach;?>
<?php echo '<tr>', $labels, '</tr><tr>', $values, '</tr>'; ?>
</tbody>
</table>
Я пытался установить $_i = 1
и следующее утверждение, но оно не сработало , Что я делаю не так?
if ($_i % 3 == 0){
echo "</tr><tr>";
}
$_i++;