最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - price of product can't return when get data of product in functions.php

programmeradmin4浏览0评论

i create custom function to get all data of product to one category in functions.php

function get_products()
{
  $cat_id = $_POST['category'];
  $args = array(
  'post_type'             => 'product',
  'post_status'           => 'publish',
  'ignore_sticky_posts'   => 1,
  'posts_per_page'        => '12',
  'tax_query'             => array(
   array(
    'taxonomy'      => 'product_cat',
    'field' => 'term_id', //This is optional, as it defaults to 'term_id'
    'terms'         => $cat_id,
    'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
   ),
   array(
    'taxonomy'      => 'product_visibility',
    'field'         => 'slug',
    'terms'         => 'exclude-from-catalog', // Possibly 'exclude-from-search' too
    'operator'      => 'NOT IN'
  )
)
);
$wc_query = new WP_Query($args);

if ($wc_query->have_posts()) : 
  while ( $wc_query->have_posts() ) 
    $wc_query->the_post();
    var_dump($product->get_regular_price());
  endwhile;
endif;
//echo json_encode($products);

wp_die();
}

the result is string(0)"" to the price

what is the mistake???

发布评论

评论列表(0)

  1. 暂无评论