• Resolved quietmanvp2

    (@quietmanvp2)


    HELP!! I have spent hours trying to resolve this issue and I can’t find a solution.

    I have products with variations. Without choosing a variation option, you can click “add to cart” button and the product gets added to the cart. (There is no alert/popup indicating that a variation needs to be chosen). Then a “generic” product gets added to the cart without the variation. I am unable to fulfill orders without it. Everything is set up properly for product attributes and variations on the back end.

    This is the snippet from chrome dev tools for the page’s submit button when a variation is not chosen and yet it adds it still adds it to the cart.
    (Note that the variation id value = 0 which I would assume means that it is “empty”

    <button type=”submit” class=”single_add_to_cart_button button alt”></button>
    <input type=”hidden” name=”add-to-cart” value=”5963″>
    <input type=”hidden” name=”product_id” value=”5963″>
    <input type=”hidden” name=”variation_id” class=”variation_id” value=”0″>

    PLEASE HELP!!

    Here is the validation filter function from the class-wc-form-handler.php
    /**
    * Handle adding variable products to the cart.
    *
    * @since 2.4.6 Split from add_to_cart_action.
    * @throws Exception If add to cart fails.
    * @param int $product_id Product ID to add to the cart.
    * @return bool success or not
    */
    private static function add_to_cart_handler_variable( $product_id ) {
    $variation_id = empty( $_REQUEST[‘variation_id’] ) ? ” : absint( wp_unslash( $_REQUEST[‘variation_id’] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
    $quantity = empty( $_REQUEST[‘quantity’] ) ? 1 : wc_stock_amount( wp_unslash( $_REQUEST[‘quantity’] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
    $variations = array();

    foreach ( $_REQUEST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
    if ( ‘attribute_’ !== substr( $key, 0, 10 ) ) {
    continue;
    }

    $variations[ sanitize_title( wp_unslash( $key ) ) ] = wp_unslash( $value );
    }

    $passed_validation = apply_filters( ‘woocommerce_add_to_cart_validation’, true, $product_id, $quantity, $variation_id, $variations );

    if ( $passed_validation && false !== WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations ) ) {
    wc_add_to_cart_message( array( $product_id => $quantity ), true );
    return true;
    }

    return false;
    }

    • This topic was modified 4 years, 4 months ago by quietmanvp2.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    Just to make sure: Do you have a any default form values configured here: https://d.pr/i/qYe2KA?

    Also, can you share a copy of your status report as found under **WooCommerce > Status**?

    Thread Starter quietmanvp2

    (@quietmanvp2)

    Hi,

    No default form values are set. Also, the page that I chose to show the issue is just one among the products with variations…

    Greg

    Here is the status report:

    
    ### WordPress Environment ###
    
    WordPress address (URL): https://quietmanvapors.com
    Site address (URL): https://quietmanvapors.com
    WC Version: 4.5.2
    REST API Version: ? 4.5.2
    WC Blocks Version: ? 3.1.0
    Action Scheduler Version: ? 3.1.6
    WC Admin Version: ? 1.5.0
    Log Directory Writable: ?
    WP Version: 5.5.1
    WP Multisite: –
    WP Memory Limit: 256 MB
    WP Debug Mode: –
    WP Cron: ?
    Language: en_US
    External object cache: ?
    
    ### Server Environment ###
    
    Server Info: Apache
    PHP Version: 7.3.23
    PHP Post Max Size: 260 MB
    PHP Time Limit: 0
    PHP Max Input Vars: 1000
    cURL Version: 7.72.0
    OpenSSL/1.1.1h
    
    SUHOSIN Installed: –
    MySQL Version: 5.6.41-84.1
    Max Upload Size: 256 MB
    Default Timezone is UTC: ?
    fsockopen/cURL: ?
    SoapClient: ?
    DOMDocument: ?
    GZip: ?
    Multibyte String: ?
    Remote Post: ?
    Remote Get: ?
    
    ### Database ###
    
    WC Database Version: 4.5.2
    WC Database Prefix: wp_
    Total Database Size: 77.50MB
    Database Data Size: 40.86MB
    Database Index Size: 36.64MB
    wp_woocommerce_sessions: Data: 0.34MB + Index: 0.01MB + Engine MyISAM
    wp_woocommerce_api_keys: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_woocommerce_attribute_taxonomies: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_woocommerce_downloadable_product_permissions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_woocommerce_order_items: Data: 0.77MB + Index: 0.34MB + Engine MyISAM
    wp_woocommerce_order_itemmeta: Data: 3.57MB + Index: 2.75MB + Engine MyISAM
    wp_woocommerce_tax_rates: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_woocommerce_tax_rate_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_woocommerce_shipping_zones: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_woocommerce_shipping_zone_locations: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_woocommerce_shipping_zone_methods: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_woocommerce_payment_tokens: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_woocommerce_payment_tokenmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_woocommerce_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_actionscheduler_actions: Data: 0.36MB + Index: 0.16MB + Engine MyISAM
    wp_actionscheduler_claims: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_actionscheduler_groups: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_actionscheduler_logs: Data: 0.29MB + Index: 0.19MB + Engine MyISAM
    wp_bwf_contact: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
    wp_bwf_contact_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
    wp_bwf_wc_customers: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_commentmeta: Data: 0.39MB + Index: 0.41MB + Engine InnoDB
    wp_comments: Data: 4.52MB + Index: 4.84MB + Engine InnoDB
    wp_ewwwio_images: Data: 1.40MB + Index: 0.20MB + Engine MyISAM
    wp_gpi_api_error_logs: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_gpi_custom_urls: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_gpi_page_blacklist: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_gpi_page_reports: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_gpi_page_stats: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_gpi_summary_snapshots: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_itro_plugin_field: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_itro_plugin_option: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_itsec_lockouts: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_itsec_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_itsec_temp: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_login_security_solution_fail: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_options: Data: 4.47MB + Index: 0.27MB + Engine InnoDB
    wp_popover_ip_cache: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_postmeta: Data: 14.55MB + Index: 18.06MB + Engine InnoDB
    wp_posts: Data: 2.52MB + Index: 0.97MB + Engine InnoDB
    wp_redirection_404: Data: 0.02MB + Index: 0.02MB + Engine MyISAM
    wp_redirection_groups: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_redirection_items: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_redirection_logs: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_redirection_modules: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_termmeta: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_usermeta: Data: 3.52MB + Index: 6.03MB + Engine InnoDB
    wp_users: Data: 0.22MB + Index: 0.23MB + Engine InnoDB
    wp_wce_editor_content: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wc_admin_notes: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wc_admin_note_actions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wc_category_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wc_customer_lookup: Data: 0.26MB + Index: 0.24MB + Engine MyISAM
    wp_wc_download_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wc_order_coupon_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wc_order_product_lookup: Data: 0.50MB + Index: 0.46MB + Engine MyISAM
    wp_wc_order_stats: Data: 0.37MB + Index: 0.25MB + Engine MyISAM
    wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine MyISAM
    wp_wc_product_meta_lookup: Data: 0.01MB + Index: 0.03MB + Engine MyISAM
    wp_wc_reserved_stock: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wc_tax_rate_classes: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_wc_webhooks: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_weu_group27: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_weu_subscribers: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_weu_unsubscriber: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_weu_user_notification: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfBadLeechers: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfBlockedIPLog: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfBlocks: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfBlocksAdv: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfConfig: Data: 0.01MB + Index: 0.01MB + Engine MyISAM
    wp_wfco_report_views: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
    wp_wfCrawlers: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfFileMods: Data: 1.16MB + Index: 0.31MB + Engine MyISAM
    wp_wfHits: Data: 0.54MB + Index: 0.10MB + Engine MyISAM
    wp_wfHoover: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfIssues: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfLeechers: Data: 0.01MB + Index: 0.02MB + Engine MyISAM
    wp_wfLockedOut: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfLocs: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfLogins: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfNet404s: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfReverseCache: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfScanners: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_wfStatus: Data: 0.09MB + Index: 0.04MB + Engine MyISAM
    wp_wfThrottleLog: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wfVulnScanners: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_woocommerce_termmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wpcreviews: Data: 0.01MB + Index: 0.00MB + Engine MyISAM
    wp_wpforms_tasks_meta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_wpmm_subscribers: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
    wp_yoast_indexable: Data: 0.73MB + Index: 0.29MB + Engine MyISAM
    wp_yoast_indexable_hierarchy: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_yoast_migrations: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    wp_yoast_primary_term: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    wp_yoast_seo_links: Data: 0.02MB + Index: 0.01MB + Engine MyISAM
    wp_yoast_seo_meta: Data: 0.01MB + Index: 0.01MB + Engine MyISAM
    
    ### Post Type Counts ###
    
    amn_exact-metrics: 1
    attachment: 196
    mailpoet_page: 1
    mc4wp-form: 1
    ml-slider: 46
    nav_menu_item: 46
    oembed_cache: 2
    page: 16
    product: 23
    product_variation: 223
    quantity-rule: 1
    revision: 47
    shop_order: 4940
    shop_order_refund: 65
    woocustomemails: 1
    wooframework: 568
    wpcr3_review: 59
    wpforms: 2
    
    ### Security ###
    
    Secure connection (HTTPS): ?
    Hide errors from visitors: ?
    
    ### Active Plugins (15) ###
    
    AddToAny Share Buttons: by AddToAny – 1.7.42
    amr shortcode any widget: by anmari – 3.7
    Customer Reviews for WooCommerce: by Customer Reviews – 3.128
    Google Webfonts For Woo Framework: by Jason Judge – 1.6.4
    Google Pagespeed Insights: by Matt Keys – 4.0.3
    Regenerate Thumbnails: by Alex Mills (Viper007Bond) – 3.1.3
    W3 Total Cache: by BoldGrid – 0.15.1
    WooCommerce Weight Based Shipping: by weightbasedshipping.com – 5.3.6
    Print Invoice & Delivery Notes for WooCommerce: by Tyche Softwares – 4.6.0
    WooCommerce - StampscomEndicia Integration: by Stamps.comEndicia – 2.0.0 – Installed version not tested with active version of WooCommerce 4.5.2
    WooCommerce WooCart Pro: by Festi Team – 2.5 – Installed version not tested with active version of WooCommerce 4.5.2
    WooCommerce: by Automattic – 4.5.2
    Network Merchants Inc Gateway for WooCommerce: by PatSaTECH – 1.8.0.0 – Installed version not tested with active version of WooCommerce 4.5.2
    Yoast SEO: by Team Yoast – 15.0
    WP Maintenance Mode: by Designmodo – 2.2.4
    
    ### Inactive Plugins (4) ###
    
    Rearrange Woocommerce Products: by Aslam Doctor – 2.3.1 – Installed version not tested with active version of WooCommerce 4.5.2
    Repeat Order for Woocommerce: by polyres – 1.2.0 – Installed version not tested with active version of WooCommerce 4.5.2
    reSmush.it Image Optimizer: by reSmush.it – 0.3.11
    YITH WooCommerce Zoom Magnifier: by YITH – 1.3.19
    
    ### Dropin Plugins (2) ###
    
    advanced-cache.php: advanced-cache.php
    object-cache.php: object-cache.php
    
    ### Settings ###
    
    API Enabled: ?
    Force SSL: ?
    Currency: USD ($)
    Currency Position: left
    Thousand Separator: ,
    Decimal Separator: .
    Number of Decimals: 2
    Taxonomies: Product Types: external (external)
    grouped (grouped)
    simple (simple)
    variable (variable)
    
    Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
    exclude-from-search (exclude-from-search)
    featured (featured)
    outofstock (outofstock)
    rated-1 (rated-1)
    rated-2 (rated-2)
    rated-3 (rated-3)
    rated-4 (rated-4)
    rated-5 (rated-5)
    
    Connected to WooCommerce.com: –
    
    ### WC Pages ###
    
    Shop base: #9 - /shop/
    Cart: #10 - /cart/
    Checkout: #11 - /checkout/
    My account: #12 - /my-account/
    Terms and conditions: #745 - /terms-and-conditions/
    
    ### Theme ###
    
    Name: Mystile-child
    Version: 1.3.2
    Author URL: https://www.woothemes.com
    Child Theme: ?
    Parent Theme Name: Mystile
    Parent Theme Version: 1.3.2 – 1.3.19 is available
    Parent Theme Author URL: https://www.woothemes.com
    WooCommerce Support: ?
    
    ### Templates ###
    
    Overrides: mystile-child/woocommerce/archive-product.php
    mystile-child/woocommerce/cart/cart-empty.php
    mystile-child/woocommerce/cart/cart-shipping.php
    mystile-child/woocommerce/cart/cart-totals.php
    mystile-child/woocommerce/cart/cart.php
    mystile-child/woocommerce/cart/mini-cart.php
    mystile-child/woocommerce/cart/proceed-to-checkout-button.php
    mystile-child/woocommerce/checkout/form-billing.php
    mystile-child/woocommerce/checkout/form-checkout.php
    mystile-child/woocommerce/checkout/form-login.php
    mystile-child/woocommerce/checkout/form-pay.php
    mystile-child/woocommerce/checkout/form-shipping.php
    mystile-child/woocommerce/checkout/payment.php
    mystile-child/woocommerce/checkout/review-order.php
    mystile-child/woocommerce/checkout/terms.php
    mystile-child/woocommerce/checkout/thankyou.php
    mystile-child/woocommerce/content-product.php
    mystile-child/woocommerce/content-single-product.php
    mystile-child/woocommerce/myaccount/form-edit-account.php
    mystile-child/woocommerce/myaccount/form-edit-address.php
    mystile-child/woocommerce/myaccount/form-login.php
    mystile-child/woocommerce/myaccount/form-lost-password.php
    mystile-child/woocommerce/myaccount/my-account.php
    mystile-child/woocommerce/myaccount/my-address.php
    mystile-child/woocommerce/myaccount/my-orders.php
    mystile-child/woocommerce/myaccount/view-order.php
    mystile-child/woocommerce/order/form-tracking.php
    mystile-child/woocommerce/order/order-again.php
    mystile-child/woocommerce/order/order-details-customer.php
    mystile-child/woocommerce/order/order-details-item.php
    mystile-child/woocommerce/order/order-details.php
    mystile-child/woocommerce/order/tracking.php
    mystile-child/woocommerce/single-product/price.php
    mystile-child/woocommerce/single-product/tabs/description.php
    mystile-child/woocommerce/single-product.php
    
    
    • This reply was modified 4 years, 4 months ago by quietmanvp2.
    • This reply was modified 4 years, 4 months ago by quietmanvp2.
    Plugin Support Thu P. a11n

    (@thup90)

    Hi there,

    I tested by adding the variable product to cart, I was able to add the variation to cart as well, so I trust you figured this out.

    If you still encounter issue with this, this sounds like it could be a code conflict on your site that causes it. To test, please follow the instruction in this link: https://docs.woocommerce.com/document/woocommerce-self-service-guide/

    Thread Starter quietmanvp2

    (@quietmanvp2)

    Hi,

    I did not figure out anything (I wish I did). There has never been an issue choosing a product variation and adding it to the cart. The problem is that you can add a product to the cart WITHOUT choosing a variation which is something that should NOT be allowed to happen. There should be a flag that pops and tells the customer to choose a variation. The sale cannot be fulfilled because I don’t know which variation of the product they want.

    I have checked the system status and everything is up to date.

    • This reply was modified 4 years, 4 months ago by quietmanvp2.
    • This reply was modified 4 years, 4 months ago by quietmanvp2.
    Plugin Support Damianne P (a11n)

    (@drwpcom)

    Hi @quietmanvp2. Sorry we missed your last response.

    Definitely, a customer should not be able to add a product to the cart without selecting a variation. I got an error message when I tried to do so.

    Have you managed to resolve the issue? If not, I noticed that you have W3 Total Cache activated on your site. Please make sure that you have deactivated caching for the Cart, Checkout and My Account pages as explained in this guide.

    You may have already solved the issue. If there is no update on this thread within the next week, we will go ahead and resolve the thread. In that case, please feel free to start a new thread if you have additional questions.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Woocommerce variation validation NOT working – add to cart’ is closed to new replies.