Woocommerce产品变化布局更改

Woocommerce产品变化布局更改,woocommerce,Woocommerce,我想在单一产品页面上做一个关于显示变体的小改动 通常,变体显示为html,如下所示 <table class="variations" cellspacing="0"> <tbody> <tr> <td class="label"><label for="group-size">Group Size</label></td> <td class="value"> <select id=

我想在单一产品页面上做一个关于显示变体的小改动

通常,变体显示为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>

组大小
选择一个选项
1人
2人
活动类型
选择一个选项
行走
有车
但是我想要这样的

    <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>

组大小
选择一个选项
1人
2人
活动类型
选择一个选项
行走
有车
意味着我想把标签放在选项上方的一行中


我们如何做到这一点

我自己找到了解决办法

中有variable.php wp内容/插件/woocommerce/模板/单一产品/添加到购物车

我打开了那个文件

ı已经变了

<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>


永远不要修改插件核心文件。@Daniel,所以为OP提供一个替代方案,他已经很好地报告了这个问题并给出了答案。Woocommerce的钩子和动作系统将HTML放得到处都是。坦率地说,如果一个核心文件可以被修改以创建新的静态HTML,那么从性能角度来看,这可能比一堆remove_操作和add_操作要好。也许最好只是指出OP在更新Woocommerce时需要小心,或者更好地将其复制到主题的文件中(尽管这会带来一些开销)。@MikeA-不,不是。这是一种可怕的做法,你不应该支持它。永远不要修改插件文件。要么通过钩子覆盖您需要的内容,要么利用Woocommerce的模板(通过在主题文件中创建Woocommerce目录,您可以覆盖模板文件)。请参见类似于“永远不要修改节点_模块中的文件”的内容。。。这是一个非常相似的概念。
<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>