虽然听起来很简单,但我不知道它是如何运行的:我如何通过SQL通过其ID为产品选择产品的可见性?
这就是我所拥有的:
global $wpdb;
$result = $wpdb->get_col( "SELECT catalog_visibility FROM XXX WHERE product_id = 3" );
答案 0 :(得分:1)
以下SQL查询将显示给定产品ID的目录可见性,如下所示:
$product_id = 37;
$result = $wpdb->get_var( "
SELECT COUNT(tr.object_id)
FROM {$wpdb->prefix}terms as t
JOIN {$wpdb->prefix}term_taxonomy AS tt ON t.term_id = tt.term_id
JOIN {$wpdb->prefix}term_relationships AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
WHERE t.name = 'exclude-from-catalog'
AND tr.object_id = $product_id
" );
echo $result; // 0 for visible | 1 for not visible
经过测试可以正常工作。
它将给出:
1
用于隐藏在目录(商店和档案页面)中0
用于在目录(商店和档案页面)中可见