1. Welcome to the Upload WP Community Forums!  This is the best place to get premium WordPress and WooCommerce support.  Please take a look around and join the Upload WP Community for FREE today!

Product Page: Attributes and Quantity don't added to cart

Discussion in 'Category & Product Setup' started by Roberto, Feb 3, 2017.

  1. Roberto

    Roberto New Member Updated Profile

    Hi, I'm building a custom Wooommerce template, I have a problem with single product page, I added attributes in a select input: when I click on "add to cart button", the product is correct added to cart but the quantity and attributes weren't add to cart.

    What's the problem? I added the complete code of the single-product.php

    Thank you in advance,
    Regards,
    Roberto

    PHP:
    <?php
    /**
    * The Template for displaying all single products
    *
    * This template can be overridden by copying it to yourtheme/woocommerce/single-product.php.
    *
    * HOWEVER, on occasion WooCommerce will need to update template files and you
    * (the theme developer) will need to copy the new files to your theme to
    * maintain compatibility. We try to do this as little as possible, but it does
    * happen. When this occurs the version of the template file will be bumped and
    * the readme will list any important changes.
    *
    * @see        https://docs.woocommerce.com/document/template-structure/
    * @author        WooThemes
    * @package    WooCommerce/Templates
    * @version    1.6.4
    */

    if ( ! defined'ABSPATH' ) ) {
        exit; 
    // Exit if accessed directly
    }

    global 
    $product;



    get_header'shop' ); ?>

        <?php
            
    /**
            * woocommerce_before_main_content hook.
            *
            * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
            * @hooked woocommerce_breadcrumb - 20
            */
            
    do_action'woocommerce_before_main_content' );
        
    ?>

    <?php
        
    // Availability
        
    $availability      $product->get_availability();
        
    $availability_html = empty( $availability['availability'] ) ? '' '<p class="stock ' esc_attr$availability['class'] ) . '">' esc_html$availability['availability'] ) . '</p>';

        echo 
    apply_filters'woocommerce_stock_html'$availability_html$availability['availability'], $product );
    ?>

    <?php if ( $product->is_in_stock() ) : ?>

        <?php do_action'woocommerce_before_add_to_cart_form' ); ?>

        <form class="cart" method="post" enctype='multipart/form-data'>
            <?php do_action'woocommerce_before_add_to_cart_button' ); ?>
         
    <div class="container">
        <div class="row"> 
            <div class="col-md-12">
            <div class="altezza-17"></div>
                <?php the_title'<h1 itemprop="name" class="titolo-prodotto">''</h1>' ); ?>
             
             
                <div class="altezza-20"></div>
             
            </div>
        </div>
    </div> 

     
     
    <div class="container">
        <div class="row"> 
                    <div class="col-md-4">
                <div class="row">
             
                    <div class="col-md-12">
                 
                    <?php
            
    if ( has_post_thumbnail() ) {
                
    $attachment_count count$product->get_gallery_attachment_ids() );
                
    $gallery          $attachment_count '[product-gallery]' '';
                
    $props            wc_get_product_attachment_propsget_post_thumbnail_id(), $post );
                
    $image            get_the_post_thumbnail$post->IDapply_filters'single_product_large_thumbnail_size''shop_single' ), array(
                    
    'title'    => $props['title'],
                    
    'alt'    => $props['alt'],
                ) );
                echo 
    apply_filters(
                    
    'woocommerce_single_product_image_html',
                    
    sprintf(
                        
    '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" data-rel="prettyPhoto%s">%s</a>',
                        
    esc_url$props['url'] ),
                        
    esc_attr$props['caption'] ),
                        
    $gallery,
                        
    $image
                    
    ),
                    
    $post->ID
                
    );
            } else {
                echo 
    apply_filters'woocommerce_single_product_image_html'sprintf'<img src="%s" alt="%s" />'wc_placeholder_img_src(), __'Placeholder''woocommerce' ) ), $post->ID );
            }

            
    //do_action( 'woocommerce_product_thumbnails' );
        
    ?>
                     
                    </div>
                </div>
            </div>
         
    <div class="col-md-8">
        <div class="row"> 
            <div class="col-md-4">
            <img src="<?php echo get_template_directory_uri(); ?>/icone/check.png" width="30px">
            </div>
         
            <div class="col-md-8">
            <p class="prod-disponibile-varianti">&nbsp;Prodotto disponibile </p>
            </div>
        </div>

    <div class="row"> 
            <div class="col-md-3">
            <span class="prezzo-prodotto-barrato">
                <s><?php echo $product->get_regular_price()?><?php echo get_woocommerce_currency_symbol("EUR");?></s>
            </span>
            <span class="prezzo-prodotto" style="padding-right:25px;"><?php echo $product->get_sale_price() ?><?php echo get_woocommerce_currency_symbol("EUR");?></span>


            </div>
         
            <div class="col-md-3" style="padding-left: 30px;">
         
                <div class="row">
             
                <?php
                
    if ( ! $product->is_sold_individually() ) {
                    
    woocommerce_quantity_input( array(
                        
    'min_value'  => apply_filters'woocommerce_quantity_input_min'1$product ),
                        
    'max_value'  => apply_filters'woocommerce_quantity_input_max'$product->backorders_allowed() ? '' $product->get_stock_quantity(), $product ),
                        
    'input_value' => ( isset( $_POST['quantity'] ) ? wc_stock_amount$_POST['quantity'] ) : )
                    ) );
                }
            
    ?>
             
                </div>
         
            </div>
         
         
    </div>

    <div class="altezza-20"></div>
                <?php the_content(); ?>
    <?php
    // Get product attributes
    $attributes $product->get_attributes();

    if (  
    $attributes ) {
    ?>

    <div class="altezza-20"></div>
    Scegli la variante che fa per te
    <div class="altezza-20"></div>

    <?php
    }
    ?>

    <div class="row">
                 

                     
    <?php             
    // Get product attributes
    $attributes $product->get_attributes();

    if ( ! 
    $attributes ) {
        
    //echo "No attributes";
    }

    foreach ( 
    $attributes as $attribute ) {
    ?>
    <div class="col-md-6">
    <?php echo $attribute['name'] . ": "?>
    <div class="select-style">

    <?php

            
    //echo $attribute['name'] . ": ";
            
    $product_attributes = array();
            
    $product_attributes explode('|',$attribute['value']);

            
    $attributes_dropdown '<select><option>Seleziona</option>';
            
    ?>
         
            <?php

            
    foreach ( $product_attributes as $pa ) {
         
       
                
    $attributes_dropdown .= '<option value="' $pa '">' $pa '</option>';
            }

            
    $attributes_dropdown .= '</select>';

            echo 
    $attributes_dropdown;
            
    ?>
    </div>

    <div class="altezza-20"></div>

    </div>
    <?php       
    }
    ?>
    <?php do_action
    'woocommerce_after_add_to_cart_button' ); ?>

        </form>

        <?php do_action'woocommerce_after_add_to_cart_form' ); ?>

    <?php endif; ?> 
                 
                </div>
                <!-- /prima riga -->
             
                <div class="altezza-20"></div>
             
             
    <div class="row altezza-40">
                    <div class="col-md-6">
                    <!-- riempitivo -->
                    </div>
                 
                    <div class="col-md-6" style="padding-left: 28px;">
                    <div class="row">
                     
                        <div class="hidden-xs hidden-sm col-md-9" style="padding-left: 20px;">


    <?php
    get_template_part
    ('btk-parts/button-single-product')
    ?>
                        </div>
                     
                        <div class="hidden-ms hidden-lg text-center col-md-9">
                            <!-- riempitivo -->
                        </div>
                     
                        </div>
                 
                    </div>
                </div>                         
            </div>
        </div>
    </div>


    <div class="pagina-attrib-margin-top container">
        <div class="row">
            <div class="col-md-12">
            <!-- pannello -->
            <div class="wrapper">
      <div class="tabs">
        <div class="tab" >
          <input type="radio" name="css-tabs" id="tab-1" checked class="tab-switch">
          <label for="tab-1" class="tab-label">Descrizione</label>
          <div class="tab-content">
              <?php the_title'<h2 itemprop="name" class="titolo-prodotto">''</h2>' ); ?>
         
                <div class="altezza-20"></div>
             
                <?php echo woocommerce_template_single_excerpt(); ?>
                <?php the_content(); ?>
             
             
       
          </div>
       
        </div>
        <div class="tab">
          <input type="radio" name="css-tabs" id="tab-2" class="tab-switch">
          <label for="tab-2" class="tab-label">Recensioni</label>
          <div class="tab-content">
          <div class="altezza-20"></div>
                <?php
    get_template_part
    ('btk-parts/recensioni')
    ?>
             
        </div>
        </div>
     

     
      </div>

    </div>
            <!-- pannello -->
         
            </div>
        </div>
    </div> 

    <?php
    echo woocommerce_output_related_products();
    ?>
        <?php
            
    /**
            * woocommerce_after_main_content hook.
            *
            * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
            */
            
    do_action'woocommerce_after_main_content' );
        
    ?>

        <?php
            
    /**
            * woocommerce_sidebar hook.
            *
            * @hooked woocommerce_get_sidebar - 10
            */
            
    do_action'woocommerce_sidebar' );
        
    ?>


    <?php get_footer'shop' ); ?>