【问题标题】:Display the counter of the product beside the cart button在购物车按钮旁边显示产品的柜台
【发布时间】:2016-08-19 09:13:17
【问题描述】:

如何在我的产品页面(不是产品详情页面)的购物车按钮旁边添加计数器,它会如下图所示 有人可以告诉我应该使用哪个插件或任何其他建议吗? 提前谢谢你!

【问题讨论】:

标签: wordpress woocommerce


【解决方案1】:

要在商店存档页面中显示简单产品的数量输入字段,您可以将以下代码添加到活动主题的 functions.php 文件中。

/**
 * Code should be placed in your theme functions.php file.
 */
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
    if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
        $html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
        $html .= woocommerce_quantity_input( array(), $product, false );
        $html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
        $html .= '</form>';
    }
    return $html;
}

【讨论】:

    【解决方案2】:

    我在不久前从事的一个项目中使用了它。这可以满足您的需要并且很容易理解:https://gist.github.com/JeroenSormani/a3325bdbca57f59690c1#file-woocommerce-archive-page-quantity-field-php

    因此,您只需将其添加到 functions.php 并刷新...您可能需要这样做:

    .archive .quantity {
        display: inline-block;
    }
    

    所以它显示正确。

    【讨论】:

      猜你喜欢
      • 2018-08-11
      • 2019-06-30
      • 2021-09-20
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-10
      相关资源
      最近更新 更多