【问题标题】:Display always stock status without quantity in WooCommerce在 WooCommerce 中始终显示没有数量的库存状态
【发布时间】:2018-01-20 11:08:05
【问题描述】:

我想显示产品库存状态,显示剩余数量。

现在,标准的 WooCommerce 库存显示以及我目前发现的插件(WooCommerce Booster 等)显示数量或显示数量和短语“库存”的“一揽子交易”。

换句话说,

我有:“有 5 个”

我想显示:“有货”

这可能吗?如果有,怎么做?

【问题讨论】:

    标签: wordpress woocommerce product stock product-quantity


    【解决方案1】:

    已解决。

    Woocommerce -> 设置 -> 产品 -> 库存 -> 库存显示格式。

    ...不敢相信我以前没见过。

    【讨论】:

      【解决方案2】:

      如果您对“有货”自定义消息有疑问,请尝试以下代码:

      add_filter( 'woocommerce_get_availability', 'custom_override_get_availability', 10, 2);
      
      // The hook in function $availability is passed via the filter!
          function custom_override_get_availability( $availability, $_product ) {
          if ( $_product->is_in_stock() ) $availability['availability'] = __('In Stock', 'woocommerce');
          return $availability;
          }
      

      或者这个

      //* Add stock status to archive pages
      function envy_stock_catalog() {
          global $product;
          if ( $product->is_in_stock() ) {
              echo '<div class="stock" >' . $product->get_stock_quantity() . __( ' in stock', 'envy' ) . '</div>';
          } else {
              echo '<div class="out-of-stock" >' . __( 'out of stock', 'envy' ) . '</div>';
          }
      }
      add_action( 'woocommerce_after_shop_loop_item_title', 'envy_stock_catalog' );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-15
        • 2019-04-28
        • 1970-01-01
        • 2019-09-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多