WordPress教程:WooCommerce返回特色产品ID

返回特色产品ID

function woo_get_featured_product_ids() {
  https:// Load from cache
  $featured_product_ids = get_transient( 'wc_featured_products' );
 
  https:// Valid cache found
  if ( false !== $featured_product_ids )
    return $featured_product_ids;
 
  $featured = get_posts( array(
    'post_type'      => array( 'product', 'product_variation' ),
    'posts_per_page' => -1,
    'post_status'    => 'publish',
    'meta_query'     => array(
      array(
        'key'       => '_visibility',
        'value'     => array('catalog', 'visible'),
        'compare'   => 'IN'
      ),
      array(
        'key'   => '_featured',
        'value' => 'yes'
      )
    ),
    'fields' => 'id=>parent'
  ) );
 
  $product_ids = array_keys( $featured );
  $parent_ids  = array_values( $featured );
  $featured_product_ids = array_unique( array_merge( $product_ids, $parent_ids ) );
 
  set_transient( 'wc_featured_products', $featured_product_ids );
 
  return $featured_product_ids;
}

在哪里添加此代码?

将PHP代码放在主题或子主题functions.php文件的底部。

WordPress技巧

WordPress教程:WooCommerce电子邮件名称解码

2019-3-17 17:56:52

WordPress技巧

WordPress教程:WooCommerce在编辑地址页面添加自定义字段

2019-3-17 17:59:39

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索