Plugin Directory

Changeset 3474761


Ignore:
Timestamp:
03/04/2026 05:21:33 PM (3 weeks ago)
Author:
themefic
Message:

3.3.31

Location:
instantio
Files:
272 added
4 edited

Legend:

Unmodified
Added
Removed
  • instantio/trunk/assets/app/js/instantio-script.js

    r3136060 r3474761  
    323323            cart_form = thisbutton.closest("form.cart"),
    324324            id = thisbutton.val(),
    325             product_id = cart_form.find("input[name=product_id]").val() || id,
     325            product_id = cart_form.find("input[name=product_id]").val() || cart_form.find("input[name=add-to-cart]").val() || id,
    326326            product_qty = cart_form.find("input[name=quantity]").val() || 1,
    327             variation_id = cart_form.find("input[name=variation_id]").val() || 0;
     327            variation_id = cart_form.find("input[name=variation_id]").val() || 0,
     328            asnp_wepb_items = cart_form.find("input[name=asnp_wepb_items]").val() || '';
    328329
    329330        if (cart_form.find("input[name=variation_id]").length > 0) {
     
    332333            }
    333334        }
     335
     336        var grouped_data = {};
     337
     338        cart_form.find('input[name^="quantity["]').each(function () {
     339            var name = $(this).attr('name'); // quantity[123]
     340            var matches = name.match(/\[(\d+)\]/);
     341
     342            if (matches) {
     343                var child_id = matches[1];
     344                var qty = $(this).val();
     345
     346                if (qty > 0) {
     347                    grouped_data[child_id] = qty;
     348                }
     349            }
     350        });
    334351
    335352        $.ajax({
     
    338355            data: {
    339356                action: "ins_ajax_cart_single",
     357                nonce: ins_params.ins_ajax_nonce,
    340358                product_id: product_id,
    341                 quantity: product_qty,
     359                quantity: Object.keys(grouped_data).length ? grouped_data : product_qty,
    342360                variation_id: variation_id,
     361                asnp_wepb_items: asnp_wepb_items
    343362            },
    344363            beforeSend: function (response) {
  • instantio/trunk/includes/controller/App.php

    r3313912 r3474761  
    395395    }
    396396
    397     // Ajax Single Page Add to Cart
    398397    public function ins_ajax_cart_single() {
    399         $product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_POST['product_id'] ) );
     398
     399        if ( ! isset( $_POST['nonce'] ) ||
     400            ! wp_verify_nonce( $_POST['nonce'], 'ins_ajax_nonce' ) ) {
     401            wp_send_json( [ 'error' => true ] );
     402        }
     403
     404        if ( ! isset( $_POST['product_id'] ) ) {
     405            wp_send_json( [ 'error' => true ] );
     406        }
     407
     408        $product_id   = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_POST['product_id'] ) );
     409        $variation_id = isset( $_POST['variation_id'] ) ? absint( $_POST['variation_id'] ) : 0;
     410        $product      = wc_get_product( $product_id );
     411
     412        if ( ! $product || get_post_status( $product_id ) !== 'publish' ) {
     413            wp_send_json( [ 'error' => true ] );
     414        }
     415
     416        $product_status = get_post_status( $product_id );
     417
     418        // GROUPED PRODUCT HANDLING
     419        if ( $product->is_type( 'grouped' ) ) {
     420
     421            $added = false;
     422
     423            if ( ! empty( $_POST['quantity'] ) && is_array( $_POST['quantity'] ) ) {
     424
     425                foreach ( $_POST['quantity'] as $child_id => $qty ) {
     426
     427                    $child_id = absint( $child_id );
     428                    $qty      = wc_stock_amount( $qty );
     429
     430                    if ( $qty <= 0 ) {
     431                        continue;
     432                    }
     433
     434                    $passed_validation = apply_filters(
     435                        'woocommerce_add_to_cart_validation',
     436                        true,
     437                        $child_id,
     438                        $qty
     439                    );
     440
     441                    if ( $passed_validation && get_post_status( $child_id ) === 'publish' ) {
     442
     443                        $cart_item_key = WC()->cart->add_to_cart( $child_id, $qty );
     444
     445                        if ( $cart_item_key ) {
     446                            $added = true;
     447                            do_action( 'woocommerce_ajax_added_to_cart', $child_id );
     448                        }
     449                    }
     450                }
     451            }
     452
     453            if ( $added ) {
     454
     455                if ( get_option( 'woocommerce_cart_redirect_after_add' ) === 'yes' ) {
     456                    wc_add_to_cart_message( array( $product_id => 1 ), true );
     457                }
     458
     459                $this->ins_ajax_cart_reload();
     460            }
     461
     462            wp_send_json( [
     463                'error'       => true,
     464                'product_url' => apply_filters(
     465                    'woocommerce_cart_redirect_after_error',
     466                    get_permalink( $product_id ),
     467                    $product_id
     468                )
     469            ] );
     470        }
     471
     472        // EASY PRODUCT BUNDLE (Manual Add Like Grouped)
     473        if ( $product->get_type() === 'easy_product_bundle' ) {
     474
     475            $added = false;
     476            $main_qty = ! empty( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : 1;
     477
     478            if ( ! empty( $_POST['asnp_wepb_items'] ) ) {
     479
     480                $items = json_decode( wp_unslash( $_POST['asnp_wepb_items'] ), true );
     481
     482                if ( is_array( $items ) ) {
     483
     484                    foreach ( $items as $item ) {
     485
     486                        $child_id   = isset( $item['id'] ) ? absint( $item['id'] ) : 0;
     487                        $child_qty  = isset( $item['qty'] ) ? wc_stock_amount( $item['qty'] ) : 0;
     488                        $attributes = isset( $item['attributes'] ) ? (array) $item['attributes'] : [];
     489
     490                        if ( $child_id <= 0 || $child_qty <= 0 ) {
     491                            continue;
     492                        }
     493
     494                        $child_product = wc_get_product( $child_id );
     495
     496                        if ( ! $child_product || get_post_status( $child_id ) !== 'publish' ) {
     497                            continue;
     498                        }
     499
     500                        $total_qty = $child_qty * $main_qty;
     501
     502                        $variation_id   = 0;
     503                        $variation_data = [];
     504
     505                        /*
     506                        |--------------------------------------------------------------------------
     507                        | Handle Variable Products
     508                        |--------------------------------------------------------------------------
     509                        */
     510                        if ( $child_product->is_type( 'variable' ) && ! empty( $attributes ) ) {
     511
     512                            $variation_data = [];
     513
     514                            foreach ( $attributes as $attr_key => $attr_value ) {
     515
     516                                // Convert to proper WooCommerce format
     517                                $taxonomy = wc_attribute_taxonomy_name( $attr_key );
     518
     519                                if ( taxonomy_exists( $taxonomy ) ) {
     520                                    $variation_data[ 'attribute_' . $taxonomy ] = sanitize_title( $attr_value );
     521                                } else {
     522                                    $variation_data[ 'attribute_' . sanitize_title( $attr_key ) ] = sanitize_title( $attr_value );
     523                                }
     524                            }
     525
     526                            // Find matching variation
     527                            $data_store   = \WC_Data_Store::load( 'product' );
     528                            $variation_id = $data_store->find_matching_product_variation(
     529                                $child_product,
     530                                $variation_data
     531                            );
     532                        }
     533
     534                        $price = $child_product->get_price();
     535
     536                        $cart_item_data = [
     537                            'custom_bundle_price' => $price,
     538                        ];
     539
     540                        $cart_item_key = WC()->cart->add_to_cart(
     541                            $child_id,
     542                            $total_qty,
     543                            $variation_id,
     544                            $variation_data,
     545                            $cart_item_data
     546                        );
     547
     548                        if ( $cart_item_key ) {
     549                            $added = true;
     550                            do_action( 'woocommerce_ajax_added_to_cart', $child_id );
     551                        }
     552                    }
     553                }
     554            }
     555
     556            if ( $added ) {
     557
     558                if ( get_option( 'woocommerce_cart_redirect_after_add' ) === 'yes' ) {
     559                    wc_add_to_cart_message( array( $product_id => $main_qty  ), true );
     560                }
     561
     562                $this->ins_ajax_cart_reload();
     563            }
     564
     565            wp_send_json( [
     566                'error'       => true,
     567                'product_url' => get_permalink( $product_id )
     568            ] );
     569        }
     570
     571        // SIMPLE / VARIABLE PRODUCTS
    400572        $quantity = empty( $_POST['quantity'] ) ? 1 : wc_stock_amount( $_POST['quantity'] );
    401         $variation_id = absint( $_POST['variation_id'] );
    402         $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );
    403         $product_status = get_post_status( $product_id );
    404 
    405         if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity, $variation_id ) && $product_status === 'publish' ) {
     573
     574        $passed_validation = apply_filters(
     575            'woocommerce_add_to_cart_validation',
     576            true,
     577            $product_id,
     578            $quantity,
     579            $variation_id
     580        );
     581
     582        if (
     583            $passed_validation &&
     584            $product_status === 'publish' &&
     585            WC()->cart->add_to_cart( $product_id, $quantity, $variation_id )
     586        ) {
    406587
    407588            do_action( 'woocommerce_ajax_added_to_cart', $product_id );
     
    412593
    413594            $this->ins_ajax_cart_reload();
    414 
    415         } else {
    416             $data = array(
    417                 'error' => true,
    418                 'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id ) );
    419 
    420             echo wp_send_json( $data );
    421         }
    422         wp_die();
     595        }
     596
     597        wp_send_json( [
     598            'error'       => true,
     599            'product_url' => apply_filters(
     600                'woocommerce_cart_redirect_after_error',
     601                get_permalink( $product_id ),
     602                $product_id
     603            )
     604        ] );
    423605    }
    424606
  • instantio/trunk/instantio.php

    r3456279 r3474761  
    99 * Author URI: https://themefic.com
    1010 * Tags: woocommerce cart, woocommerce checkout, woocommerce direct checkout, multistep checkout, woocommerce side cart
    11  * Version: 3.3.30
     11 * Version: 3.3.31
    1212 * Tested up to: 6.9
    1313 * Requires PHP: 7.4
     
    3535    private function define_constants() {
    3636        if ( ! defined( 'INSTANTIO_VERSION' ) ) {
    37             define( 'INSTANTIO_VERSION', '3.3.30' );
     37            define( 'INSTANTIO_VERSION', '3.3.31' );
    3838        }
    3939        define( 'INS_URL', plugin_dir_url( __FILE__ ) );
  • instantio/trunk/readme.txt

    r3456279 r3474761  
    44Requires at least: 4.0
    55Tested up to: 6.9
    6 Stable tag: 3.3.30
     6Stable tag: 3.3.31
    77WC requires at least: 7.0
    88WC tested up to: 10.5
     
    376376== Changelog ==
    377377
     378= 3.3.31 – March 04, 2026 =
     379
     380- New: Group Product Add to Cart support.
     381- New: Bundler Product Add to Cart compatibility.
     382- Improvement: Security enhancements implemented.
     383
    378384= 3.3.30 – February 08, 2026 =
    379385
Note: See TracChangeset for help on using the changeset viewer.