【问题标题】:Woocommerce How to display Product attributes with shortcode? [closed]Woocommerce 如何使用简码显示产品属性? [关闭]
【发布时间】:2021-01-25 10:11:55
【问题描述】:

我想用简码显示 Woocommerce 产品属性。

它可能看起来像标准主题样式(下面链接中的图片),但希望简码显示我在产品编辑器的“属性”选项卡中放置的内容。

https://i.stack.imgur.com/ql0Dk.png

我需要将一段代码放入我的functions.php 中,以创建一个显示产品属性的简码。有人可以帮忙吗?

【问题讨论】:

    标签: php html wordpress woocommerce shortcode


    【解决方案1】:

    使用显示当前产品的全局 $product 变量。您可以从以下位置获取属性:

    $product->get_attributes();
    

    然后您可以简单地使用 foreach 循环,并将它们显示在表格中。 喜欢

    <table>
    <?php 
      foreach($product->get_attributes() as $attribute) {
        ?>
        <tr>
           <td>Attribute name</td> <td>Attribute value</td>
        </tr>
        <?php
      }
    ?>
    </table>
    

    然后您可以使用如下插件: https://wordpress.org/plugins/insert-php-code-snippet/ 将该代码转换为快捷方式。

    【讨论】:

    • 感谢@christian 的快速回答。 Unfotionally它没有工作。 elementor 中存在服务器错误。您能否为我提供一个代码,我可以将其放入我的 functions.php 文件中以创建短代码?
    猜你喜欢
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多