商品詳細ページのWoocommerceの「数量」フィールド(カートに追加する前に数量を入力する)を非表示にし、「カートに追加」ボタンのみを表示する必要があります。これにより、数量が1になります。カートの中。その理由は、重力フォームに基づいて数量を収集するためです。
12 に答える
- 商品を編集します。
- 「在庫」をクリックします。
- 「個別販売」にチェックを入れる
商品の単一ページでそれを行う簡単な方法を見つけ、数量カウンターをカートに入れました。次のコードを functions.php に入れるだけです
add_action( 'wp_head', 'quantity_wp_head' );
function quantity_wp_head() {
if ( is_product() ) {
?>
<style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>
<?php }
}
ここで woocommerce のドキュメントを確認できます: http://docs.woothemes.com/document/remov-product-content-based-on-category/
あなたのために働くかもしれない数量セレクターを削除するための無料のプラグインがあります. http://wordpress.org/extend/plugins/woocommerce-remove-quantity-fields/
プラグインは必要ありません。たとえば、css を使用して非表示にすることができます。しかし、woocommerce では 1 つの商品しか販売できず、同じ商品をカートに追加する選択はありません。woocommerce->設定を見てください。それはすべてそこにあります。
編集する必要があるテンプレートは ですsingle-product/add-to-cart/variation-add-to-cart-button.php
。
したがって、このテンプレートを独自のテーマにコピーし、編集して数量フィールドを削除するだけです。次のようになります。
<?php
/**
* Single variation cart button
*
* @see http://docs.woothemes.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $product;
?>
<div class="woocommerce-variation-add-to-cart variations_button">
<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
<input type="hidden" name="add-to-cart" value="<?php echo absint( $product->id ); ?>" />
<input type="hidden" name="product_id" value="<?php echo absint( $product->id ); ?>" />
<input type="hidden" name="variation_id" class="variation_id" value="0" />
</div>