doude4201 2017-02-21 16:42
浏览 38
已采纳

WooCommerce:如何在循环外展示销售产品

I have created a standard php page template for our shop, that should be used on a sales page on which are only shown products that are on sale. How can I display 4 random products on sale via php?

WooCommerce have a shortcode that displays sale products, but this doesn't work if I call it via do_shortcode function.

  • 写回答

1条回答 默认 最新

  • dqnf28092 2017-02-21 17:08
    关注

    You could use your own query.

    $args = array(
    'post_type' => 'product',
    'showposts' => 4,
    'orderby'   => 'rand',
    'meta_query'   => array(
        'relation' => 'OR',
        array( // Simple products type
            'key'     => '_sale_price',
            'value'   => 0,
            'compare' => '>',
            'type'    => 'numeric'
        ),
        array( // Variable products type
            'key'     => '_min_variation_sale_price',
            'value'   => 0,
            'compare' => '>',
            'type'    => 'numeric'
        )
    )
    );
    
    $sale_products = new WP_Query( $args );
    

    Not sure why shortcode wouldn't be working.

    echo do_shortcode('[sale_products columns="4" per_page="4"]' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 matlab appdesigner私有函数嵌套整合
  • ¥15 给我一个openharmony跑通webrtc实现视频会议的简单demo项目,sdk为12
  • ¥15 vb6.0使用jmail接收smtp邮件并另存附件到D盘
  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题