추가 구매 상품을 1개~2개만 구매할 수 있도록 설정하고 싶어요.

아래의 코드를 참고하여 차일드 테마에 추가해 주시기 바랍니다.

function mshop_diy_adjust_stock_quantity( $option, $product ) {
   $option['stock_quantity'] = 2;

   return $option;
}

add_filter( 'msdp_make_dropdown_option', 'mshop_diy_adjust_stock_quantity', 99, 2 );


function mshop_diy_adjust_woocommerce_cart_item_quantity( $product_quantity, $cart_item_key, $cart_item ) {
   if ( msdp_is_set_product( $cart_item ) && ! msdp_is_set_parent( $cart_item ) ) {
      if ( msdp_cart_contains_set_parent( $cart_item['msdp_set_id'] ) ) {
         ob_start();
         ?>
            <‎span><?php echo $cart_item['quantity']; ?></span>
            <‎input type="hidden" id="<?php echo esc_attr( uniqid( 'quantity_' ) ); ?>" class="qty" name="<?php echo esc_attr( "cart[{$cart_item_key}][qty]" ); ?>" value="<?php echo $cart_item['quantity']; ?>"/>
         <?php
         $product_quantity = ob_get_clean();
      }
   }

   return $product_quantity;
}

add_filter( 'woocommerce_cart_item_quantity', 'mshop_diy_adjust_woocommerce_cart_item_quantity', 99, 3 );
Was this article helpful to you? Yes No