我在自定义构建模板中显示变体时遇到问题,每次我在循环中调用wpsc函数wpsc_have_variation_groups()
时都会出现以下php错误
commerce / wpsc-includes / product-template.php [2012年11月22日23:27:39] PHP致命错误:在/中的非对象上调用成员函数have_variation_groups()
home / tofapost / public_html / sandbox / wp / wp-content / plugins / wp-e-commerce / wpsc-includes / product-template.php 1419行。
wpsc_have_variation_groups()
在WP_Query循环中被调用,如此;
$args = array('post_type' => 'wpsc-product', 'posts_per_page' => -1);
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post();
...
<?php if (wpsc_have_variation_groups()) { ?>
<?php } ?>
...
endwhile;
奇怪的是其他wpsc函数,如wpsc_the_product_id()和wpsc_product_has_stock()工作,而没有与变体相关的函数...
任何帮助表示赞赏
由于
答案 0 :(得分:2)
这已经得到了解答。这个问题的问题在于并非显示所有代码并且使用了错误类型的循环。列出产品。
使用的答案是手动获取变体,因为循环类型不允许使用ID,因为没有需要获取的变体的标识符。为了能够使用当前代码,它需要使用不同的循环,或者更改它以便手动获得变化。在这种情况下,手动获得变化。
global $wpsc_variations;
$wpsc_variations = new wpsc_variations( get_the_ID() );
答案 1 :(得分:2)
wpsc_the_product()函数设置产品变体函数使用的全局$ wpsc_variations对象。
我认为为了使用wpsc_the_product(),您需要将查询作为全局$ wp_query,但是在打开循环后可以自己设置$ wpsc_variations:
while ($loop->have_posts()) : $loop->the_post();
global $wpsc_variations;
$wpsc_variations = new wpsc_variations( get_the_ID() );
希望能让所有产品变异功能发挥作用。
您可以参考以下位置:
我认为这可以帮助您解决问题。