• Resolved Letícia Moreira

    (@fkdarven)


    Hello, First of all, nice work with the plugin!

    I was facing a problem where simple products where being affected by plugin’s logic even though it should not consider simple products. Not sure if the situation happened just to me, but for precaution I thought it would be better to inform you.

    Currently using WordPress 6.2 and WooCommerce 7.3. I fixed it by modifying the Ycve_Public class, line 149, where it makes the validation.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thanks for your input, it was very useful. I’ve contained a slightly wider block of code within the new condition…

    /**
     * Check at checkout if any
     * 
     * @access  public
     * @since   1.0.0
     * @param   Array   $fields
     * @param   Object  $errors
     */
    public function ycve_variation_validate_dt( $fields, $errors ){
    
        foreach ( WC()->cart->cart_contents as $key => $item ) {
            
            $product_id = $item['product_id'];
            $product    = wc_get_product( $product_id );
            
            // Check if the product is a variable product
            if ( $product->is_type( 'variable' ) ) {
                $variations = $product->get_children();
                
                if( ! empty( $variations ) ){
                    foreach( $variations as $variation ){
                        $this->ycve_check_exp_date_to( $variation );
                    }
                }
            
                $newProduct     = wc_get_product( $product_id );
                $newVariations  = $newProduct->get_children();
            
                if ( ! in_array( $item['variation_id'], $newVariations ) ) {
                    
                    $name       = $item['data']->get_name();
                    $itemsCount = count( WC()->cart->get_cart() );
                    $cart_url   = wc_get_cart_url();
                    $errorMsg   = '<b>' . $name . '</b> it is really not available! already removed from cart!! <a href="' . $cart_url . '"><b>Check cart</b></a>';
                
                    if( $itemsCount > 1 ){
                        $errorMsg = 'Product: <b>' . $name . '</b> in your cart, it is really not available and already removed from cart!! <a href="' . $cart_url . '"><b>Check cart</b></a>';
                    }
                
                    $errors->add( 'validation', $errorMsg );
                }
            }
        }//cart end
    }
    
    Plugin Author yakacj

    (@yakacj)

    Hello, thanks for the bug correction! I’ll correct this in next update.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error with simple products’ is closed to new replies.