【发布时间】:2016-08-19 09:13:17
【问题描述】:
【问题讨论】:
-
但是它帮助了我在那里不容易找到它的人所以我决定在这里分享它!
标签: wordpress woocommerce
【问题讨论】:
标签: wordpress woocommerce
要在商店存档页面中显示简单产品的数量输入字段,您可以将以下代码添加到活动主题的 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;
}
【讨论】:
我在不久前从事的一个项目中使用了它。这可以满足您的需要并且很容易理解:https://gist.github.com/JeroenSormani/a3325bdbca57f59690c1#file-woocommerce-archive-page-quantity-field-php
因此,您只需将其添加到 functions.php 并刷新...您可能需要这样做:
.archive .quantity {
display: inline-block;
}
所以它显示正确。
【讨论】: