【发布时间】:2017-06-17 19:07:37
【问题描述】:
我正在使用$variations = $product->get_available_variations(); 获取产品的所有变量,并将它们显示为描述部分的表格。
它适用于大多数产品,但我发现一个产品有 3 种变体,但它显示了其中两种。
我检查了 wp_posts 表,所有 3 个变体都与该父产品相关:
SELECT id,post_parent FROM wp_posts WHERE post_parent=843 AND post_type='product_variation';
+-----+-------------+
| id | post_parent |
+-----+-------------+
| 846 | 843 |
| 849 | 843 |
| 852 | 843 |
+-----+-------------+
但是当我使用var_dump($variations); 时,该数组返回两个 ID:846 和 849。
这是我的全部功能:
function add_content_after_addtocart_button_func() {
global $product,$post;
if( $product->is_type( 'variable' ) ){
$variations = $product->get_available_variations();
if (count($variations)>0) { ?>
<div class="spb_text_column">
<table class="sf-table standard_minimal">
<tr>
<th>SKU</th>
<th>Length (cm)</th>
<th>Width (cm)</th>
<th>Height (cm)</th>
<th>Price</th>
</tr>
<?php for ($j=0; $j < count($variations); $j++) { ?>
<tr>
<td><?php echo ($variations[$j]['sku'])?$variations[$j]['sku']:$variations[$j]['name'];?></td>
<td><?php echo $variations[$j]['length'];?></td>
<td><?php echo $variations[$j]['width'];?></td>
<td><?php echo $variations[$j]['height'];?></td>
<td><?php echo number_format_i18n($variations[$j]['price']);?></td>
</tr>
<?php } ?>
</table>
</div>
<?php }
}
}
请帮忙解决这个问题。
【问题讨论】:
-
你是从后端设置产品数量吗?如果没有,请设置产品数量。
-
@OmarFaruque,是的,已经设置好了。除价格和 SKU 外,所有变体都具有相同的设置和值
标签: php wordpress woocommerce