【问题标题】:How to add out of stock products on other page in woocommerce如何在woocommerce的其他页面上添加缺货产品
【发布时间】:2016-10-20 12:13:23
【问题描述】:

我正在搜索此查询,请帮助我,我想为缺货商品创建一个类别,并且我想在产品缺货时在其中添加商品。 在一个单独的页面上,我想显示缺货的产品。也许分配一个新的缺货类别

SELECT * FROM wp_postmeta WHERE meta_key = "_stock_status" && meta_value="outofstock";

这是我在数据库中运行的查询,但我必须在页面上显示这些产品

谢谢。

【问题讨论】:

  • WooCommerce 有一个本地短代码来显示页面上的所有销售产品:docs.woocommerce.com/document/woocommerce-shortcodes/… - 你可以使用这个:[sale_products per_page="12"]
  • 谢谢大卫,但实际上我只想在单独的页面上显示缺货的产品。
  • 对不起,我完全误读了缺货出售......

标签: wordpress woocommerce


【解决方案1】:

试试这样:

<?php
global $product;
$availability = $product->get_availability();
if ($availability['availability'] == 'Out of stock') {
            // 
}
?>

【讨论】:

    【解决方案2】:

    尝试将此代码粘贴到 function.php 文件的底部,就在结束标记之前;

       /**
     * @snippet       Display All Products Out of Stock via a Shortcode - WooCommerce
     * @how-to        Get CustomizeWoo.com FREE
     * @author        Rodolfo Melogli
     * @compatible    Woo 3.6.1
     * @donate $9     https://businessbloomer.com/bloomer-armada/
     */
    
    add_shortcode( 'out_of_stock_products', 'bbloomer_out_of_stock_products_shortcode' );
    
    function bbloomer_out_of_stock_products_shortcode() {
    
       $args = array(
          'post_type' => 'product',
          'posts_per_page' => -1,
          'post_status' => 'publish',
          'meta_query' => array(
             array(
                'key' => '_stock',
                'value' => 1,
                'compare' => '<'
             )
          ),
          'fields' => 'ids',
       );
    
       $product_ids = get_posts( $args ); 
       $product_ids = implode( ",", $product_ids );
    
       return do_shortcode("[products ids='$product_ids']");
    
    }
    

    然后将短代码 [out_of_stock_products] 粘贴到您要显示已售罄产品的页面上。确保在 woocommerce 库存设置中启用缺货商品的可见性以使其正常工作。

    知道了https://businessbloomer.com/woocommerce-display-stock-products-shortcode/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-28
      • 2017-09-13
      • 2021-08-31
      • 1970-01-01
      • 2019-09-27
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多