我已经创建了一个自定义产品详细信息页面,正在尝试获取该产品的类别,但它不起作用。
我创建了一个表格,人们可以在其中填写以下问题:
你喜欢什么牌子的?
单击“下一步…”。。。
你喜欢什么型号的?
单击“下一步”,依此类推。它将根据填充的信息获取产品。
这是我的密码
if ( isset( $_REQUEST[\'product_tag\'] ) ) {
$tags = $_REQUEST[\'product_tag\'];
}
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => 1,
\'product_tag\' => $tags
);
$loop = new WP_Query( $args );
$product_count = $loop->post_count;
if ( $product_count > 0 ) :
while ( $loop->have_posts() ) :
$loop->the_post();
global $product;
global $post;
$thePostID = $post->post_title;
//echo \'<img src="\'.$woocommerce->plugin_url().\'/assets/images/placeholder.png" alt="" width="\'.$woocommerce->get_image_size(\'shop_catalog_image_width\').\'px" height="\'.$woocommerce->get_image_size(\'shop_catalog_image_height\').\'px" />\';
$terms = wp_get_object_terms($post->ID, \'product_cat\');
echo $terms->name;
// ...
endwhile;
endif;