• 18-02-2021, 09:59:21
    #1
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Merhaba.
    Woocommerce'te sepete yalnızca 1 ürün ekleme nasıl yapılabilir? İnternette bulduğum kodlar 1 ürünü 1 kere ekleme sınırı koyuyor. Ama bana gereken sadece 1 ürün ekleyebilmek. Yardımcı olabilecek biri varsa çok sevinirim.
  • 18-02-2021, 10:11:48
    #2
    Bu işinizi görebilir.

    class Allow_Only_1_Product_Cart_MYK {
        function __construct() {
            add_action( 'woocommerce_before_calculate_totals', array($this,'wcaopc_keep_only_last_cart_item'), 30, 1 );
        }
        function wcaopc_keep_only_last_cart_item( $cart ) {
            if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
            if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) return;
            $cart_items = $cart->get_cart();
            if( count($cart_items) > 1 ){
                $cart_item_keys = array_keys( $cart_items );
                $cart->remove_cart_item( reset($cart_item_keys) );
            }
        }
    }
    $plugin = new Allow_Only_1_Product_Cart_MYK();
  • 18-02-2021, 10:14:46
    #3
    akifaykan adlı üyeden alıntı: mesajı görüntüle
    Bu işinizi görebilir.

    class Allow_Only_1_Product_Cart_MYK {
        function __construct() {
         add_action( 'woocommerce_before_calculate_totals', array($this,'wcaopc_keep_only_last_cart_item'), 30, 1 );
        }
      function wcaopc_keep_only_last_cart_item( $cart ) {
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
        if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
            return;
        $cart_items = $cart->get_cart();
        if( count($cart_items) > 1 ){
            $cart_item_keys = array_keys( $cart_items );
            $cart->remove_cart_item( reset($cart_item_keys) );
         }
       }
    }
    $plugin = new Allow_Only_1_Product_Cart_MYK();
    Tam olarak istediğim çözüm buydu. Çok teşekkür ederim