Reputation: 301
I want to make a small change on the single-product page about displaying variations.
Normally variations are displayed like this as html.
<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label for="group-size">Group Size</label></td>
<td class="value">
<select id="group-size" class="" name="attribute_group-size" data-attribute_name="attribute_group-size">
<option value="">Chose an options</option>
<option value="1 Person" >1 Person</option>
<option value="2 persons" >2 persons</option>
</select>
</td>
</tr>
<tr>
<td class="label"><label for="type-of-activity">Type of Activity</label></td>
<td class="value">
<select id="tipo-de-actividad" class="" name="attribute_tipo-de-actividad" data-attribute_name="attribute_type-of-activity">
<option value="">Chose an option</option>
<option value="Walking" >Walking</option>
<option value="With car" >with car</option>
</select>
<a class="reset_variations" href="#">Clean the selections</a>
</td>
</tr>
</tbody>
</table>
But I want to have like this
<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label for="group-size">Group Size</label></td>
</tr>
<tr>
<td class="value">
<select id="group-size" class="" name="attribute_group-size" data-attribute_name="attribute_group-size">
<option value="">Chose an options</option>
<option value="1 Person" >1 Person</option>
<option value="2 persons" >2 persons</option>
</select>
</td>
</tr>
<tr>
<td class="label"><label for="type-of-activity">Type of Activity</label></td>
</tr>
<tr>
<td class="value">
<select id="tipo-de-actividad" class="" name="attribute_tipo-de-actividad" data-attribute_name="attribute_type-of-activity">
<option value="">Chose an option</option>
<option value="Walking" >Walking</option>
<option value="With car" >with car</option>
</select>
<a class="reset_variations" href="#">Clean the selections</a>
</td>
</tr>
</tbody>
</table>
Means that i wantto have the labels inside a row just above the options.
How we can do that?
Upvotes: 2
Views: 6611
Reputation: 301
I got the solution myself.
There is variable.php in wp-content/plugins/woocommerce/templates/single-product/add-to-cart
I opened that file
ı have changed
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
<td class="value">
<?php
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
echo end( $attribute_keys ) === $attribute_name ? '<a class="reset_variations" href="#">' . __( 'Clear selection', 'woocommerce' ) . '</a>' : '';
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
to
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
</tr>
<tr>
<td class="value">
<?php
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
echo end( $attribute_keys ) === $attribute_name ? '<a class="reset_variations" href="#">' . __( 'Clear selection', 'woocommerce' ) . '</a>' : '';
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
Result was as i like.
Sorry for disturbing you.
Upvotes: 5