【发布时间】:2021-01-30 12:50:32
【问题描述】:
所以我一直在努力寻找有关这方面的任何信息,但看不到任何明显的方法。我想在产品描述中有一个表格,列出我设置的某些属性。
例如,在描述中,我将在标题 A 后跟一些文本和一个具有属性 1、2 和 3 的表格,然后在标题 B 下一些文本和属性 4、5 和 6。
我认为最简单的方法是创建一个短代码,所以我尝试过并且明显错过了一些重要的东西,因为当我使用它时它根本没有显示任何东西。
add_action( 'woocommerce_single_product_summary', 'show_attribute_group_a', 45 );
add_shortcode( 'show_attributes_a', 'show_attribute_group_a' );
function show_attribute_group_a() {
global $product;
$attribute1 = $product->get_attribute('attribute1');
$attribute2 = $product->get_attribute('attribute2');
?>
<table class="">
<tr class="">
<th class="">Attribute 1</th>
<td class=""><?php echo $attribute1; ?></td>
</tr>
<tr class="">
<th class="">Attribute 2</th>
<td class=""><?php echo $attribute2; ?></td>
</tr>
</table>
<?php
}
那么我在哪里尝试拉出我使用过的属性的 slug 是正确的吗?但是,即使那部分是错误的,我仍然希望看到一张空桌子。显然存在根本性错误,我看不出是什么。
【问题讨论】:
标签: php html wordpress woocommerce shortcode