wordpress - 重新排序 WooCommerce 变体下拉列表(不是重新排序属性术语)
问题描述
我有一家商店,里面有很多简单的产品和一些可变的产品。可变产品之一具有三个可变属性,因此有三个<select>
列表可供选择:
我需要的是反转下拉菜单出现的顺序,如下所示:
- ISO总线
- 拖拉机类型
- 安装支架
我所有的搜索都只找到了重新排序<option>
属性项的方法。需要明确的是,这不是我需要的。
这是标记的示例:
<tbody>
<tr>
<td class="label"><label for="pa_mounting-brackets">Mounting Brackets</label></td>
<td class="value">
<!-- A select element with many option elements -->
</td>
</tr>
<tr>
<td class="label"><label for="pa_tractor-type">Tractor Type</label></td>
<td class="value">
<!-- A select element with many option elements -->
</td>
</tr>
<tr>
<td class="label"><label for="pa_isobus">ISObus</label></td>
<td class="value">
<!-- A select element with two option elements -->
</td>
</tr>
<tr>
<td class="label"></td>
<td class="value">
<div class="single_variation_price_reset">
<div class="single_variation_wrap">
<div class="avada-variation single_variation" style="display: none;"></div>
</div>
<a class="reset_variations" href="#" style="visibility: hidden;">Clear selection</a></div>
</td>
</tr>
</tbody>
</table>
display: flex;
我可以使用 CSS和属性对表格行重新排序order
,但每个<tr>
元素上没有唯一标识符。我必须仅根据使用第 n 个选择器的元素顺序来定位我的 CSS。
是否有我缺少的实现此目标的 UI 或基于过滤器的方法?
解决方案
通常情况下,用语言提出问题会导致我找到一种解决方案。我的商店正在使用 Avada,有问题的 HTML 来自主题模板之一,而不是原版 WooCommerce。
我将 /wp-content/themes/Avada/woocommerce/single-product/add-to-cart/variable.php 复制到我的子主题 /wp-content/themes/Avada-Child-Theme/woocommerce/single-product/ add-to-cart/variable.php 并找到以下内容:
原来的:
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>">
我for="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>"
从<label>
元素中复制并将其粘贴到上面的<tr>
元素中,更改for
为class
.
修改的:
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr class="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>">
<td class="label"><label for="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>">
这给了我一些选择器来瞄准我的 CSS。这是我使用 flex 重新排序的 CSS:
.single-product.woocommerce .variations > tbody {
display: flex;
flex-direction: column;
}
.single-product.woocommerce .variations > tbody > tr {
display: flex;
justify-content: space-between;
order: 99;
}
.single-product.woocommerce .variations > tbody .pa_isobus {
order: 1;
}
.single-product.woocommerce .variations > tbody .pa_tractor-type {
order: 2;
}
.single-product.woocommerce .variations > tbody .pa_mounting-brackets {
order: 3;
}
.single-product.woocommerce .variations > tbody > tr > td {
flex-basis: 50%;
}
如果你有一个更简单、更好的解决方案,我仍然很想知道。
推荐阅读
- rust - 使用`fd-find` crate列出Rust中所有名为`test`的文件夹?
- flutter - Flutter 和 firebase 云消息传递,使用 API 发送通知?
- javascript - 为什么函数的变量通过“.”在外面声明 只能通过“.”访问 函数内部?
- android - Error: Can't call startAt() or equalTo() multiple times
- typescript - 当存在类型检查问题时,来自 node_modules 的 tsc 不会引发控制台异常
- javascript - 短时间内多次调用异步函数搞乱购物车
- python - 如何在 Python 中返回带有双星/星号的 **kwargs?
- swift - 何时在 Swift 错误处理中使用异常和可选项?
- javascript - ${props.title} 在页面导航期间显示而不是在 Next.js 中显示 Title - Layout.js
- rust - “显然”无法访问的块中的“借用可能未初始化的变量”错误