【问题标题】:WooCommerce how to change the order of a single product Attributes - swapping their positionsWooCommerce 如何更改单个产品属性的顺序 - 交换它们的位置
【发布时间】:2021-05-06 21:27:46
【问题描述】:

我刚开始使用 WooCommerce,默认 WooCommerce 属性排序使用字母顺序。

是否可以更改Product -> Attributes 默认位置?

例如它们的默认位置是按字母顺序排列的:

品牌
颜色
尺寸

我想把它们改成:

尺寸
颜色
品牌

【问题讨论】:

  • 你试过devanswers.co/…吗?
  • 嗨,我想改变产品属性的位置(排序)而不是产品的属性(小,大)等。

标签: wordpress sorting woocommerce wordpress-theming woocommerce-theming


【解决方案1】:

是的,这是可能的!我会尝试override woocommerce 模板。

转到以下路径:

wp-content > plugins > woocommerce > templates > single-product > add-to-cart  

COPY "variable.php" file.

回到您的active themeactive child theme 目录,在您的目录的根目录中创建一个新文件夹并将其命名为woocommerce,它必须完全是woocommerce

然后创建与woocommerce templates 目录相同的结构。所以你的文件夹结构应该是这样的:

wp-content > themes > YOUR_ACTIVE_THEME > woocommerce > single-product > add-to-cart

PASTE "variable.php" file.

现在让我们覆盖它。打开“variable.php”并找到以下代码行(对我来说它在第 38 行):

foreach ($attributes as $attribute_name => $options) : ?>

找到后,将$attributes 数组包装到array_reverse() php 函数中!所以它会是这样的:

foreach (array_reverse($attributes) as $attribute_name => $options) : ?>

输出将是:

尺寸
颜色
品牌

代替

品牌
颜色
尺寸

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多