{"id":3245,"date":"2014-03-20T21:06:24","date_gmt":"2014-03-20T21:06:24","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/20\/woocommerce-missing-add-to-cart-button-collection-of-common-programming-errors-2\/"},"modified":"2014-03-20T21:06:24","modified_gmt":"2014-03-20T21:06:24","slug":"woocommerce-missing-add-to-cart-button-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/20\/woocommerce-missing-add-to-cart-button-collection-of-common-programming-errors-2\/","title":{"rendered":"woocommerce missing add-to-cart button-Collection of common programming errors"},"content":{"rendered":"<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/ACXdx.jpg?s=32&amp;g=1\" \/><br \/>\nDana Bouchard<\/p>\n<p>Updated WordPress to newest version and lost our Add to Cart Button. I&#8217;ve been searching everywhere for a solution and tried the ones I have found.<\/p>\n<p>We do not have a backup prior to updating unfortunately : \/<\/p>\n<p>These are the errors that show in Chrome developer tools browser when on a page with missing button.<\/p>\n<blockquote>\n<p>GET http:\/\/lifefarout.com\/wp-content\/plugins\/woocommerce\/assets\/js\/jquery-cookie\/jquery.cookie.min.js?ver=1.3.1 406 (Not Acceptable) lifefarout.com:51 Uncaught TypeError: Object function (e,t){return new x.fn.init(e,t,r)} has no method &#8216;cookie&#8217; cart-fragments.min.js:1<\/p>\n<\/blockquote>\n<p>Here are the two files that chrome complains about.<\/p>\n<p>add-to-cart-variation.js ( I know WP uses the .mini but I figured this was more legible)<\/p>\n<pre><code>\/*!\n<\/code><\/pre>\n<p>* Variations Plugin *\/ ;(function ( $, window, document, undefined ) {<\/p>\n<pre><code>$.fn.wc_variation_form = function () {\n\n    $.fn.wc_variation_form.find_matching_variations = function( product_variations, settings ) {\n        var matching = [];\n\n        for (var i = 0; i &lt; product_variations.length; i++) {\n            var variation = product_variations[i];\n            var variation_id = variation.variation_id;\n\n            if ( $.fn.wc_variation_form.variations_match( variation.attributes, settings ) ) {\n                matching.push(variation);\n            }\n        }\n        return matching;\n    }\n\n    $.fn.wc_variation_form.variations_match = function( attrs1, attrs2 ) {\n        var match = true;\n        for ( attr_name in attrs1 ) {\n            var val1 = attrs1[ attr_name ];\n            var val2 = attrs2[ attr_name ];\n            if ( val1 !== undefined &amp;&amp; val2 !== undefined &amp;&amp; val1.length != 0 &amp;&amp; val2.length != 0 &amp;&amp; val1 != val2 ) {\n                match = false;\n            }\n        }\n        return match;\n    }\n\n    \/\/ Unbind any existing events\n    this.unbind( 'check_variations update_variation_values found_variation' );\n    this.find('.reset_variations').unbind( 'click' );\n    this.find('.variations select').unbind( 'change focusin' );\n\n    \/\/ Bind events\n    $form = this\n\n            \/\/ On clicking the reset variation button\n            .on( 'click', '.reset_variations', function( event ) {\n\n                $(this).closest('.variations_form').find('.variations select').val('').change();\n\n                var $sku        = $(this).closest('.product').find('.sku');\n                var $weight     = $(this).closest('.product').find('.product_weight');\n                var $dimensions = $(this).closest('.product').find('.product_dimensions');\n\n                if ( $sku.attr( 'data-o_sku' ) )\n                    $sku.text( $sku.attr( 'data-o_sku' ) );\n\n                if ( $weight.attr( 'data-o_weight' ) )\n                    $weight.text( $weight.attr( 'data-o_weight' ) );\n\n                if ( $dimensions.attr( 'data-o_dimensions' ) )\n                    $dimensions.text( $dimensions.attr( 'data-o_dimensions' ) );\n\n                return false;\n            } )\n\n            \/\/ Upon changing an option\n            .on( 'change', '.variations select', function( event ) {\n\n                $variation_form = $(this).closest('.variations_form');\n                $variation_form.find('input[name=variation_id]').val('').change();\n\n                $variation_form\n                    .trigger( 'woocommerce_variation_select_change' )\n                    .trigger( 'check_variations', [ '', false ] );\n\n                $(this).blur();\n\n                if( $().uniform &amp;&amp; $.isFunction( $.uniform.update ) ) {\n                    $.uniform.update();\n                }\n\n            } )\n\n            \/\/ Upon gaining focus\n            .on( 'focusin touchstart', '.variations select', function( event ) {\n\n                $variation_form = $(this).closest('.variations_form');\n\n                $variation_form\n                    .trigger( 'woocommerce_variation_select_focusin' )\n                    .trigger( 'check_variations', [ $(this).attr('name'), true ] );\n\n            } )\n\n            \/\/ Check variations\n            .on( 'check_variations', function( event, exclude, focus ) {\n                var all_set             = true;\n                var any_set             = false;\n                var showing_variation   = false;\n                var current_settings    = {};\n                var $variation_form     = $(this);\n                var $reset_variations   = $variation_form.find('.reset_variations');\n\n                $variation_form.find('.variations select').each( function() {\n\n                    if ( $(this).val().length == 0 ) {\n                        all_set = false;\n                    } else {\n                        any_set = true;\n                    }\n\n                    if ( exclude &amp;&amp; $(this).attr('name') == exclude ) {\n\n                        all_set = false;\n                        current_settings[$(this).attr('name')] = '';\n\n                    } else {\n\n                        \/\/ Encode entities\n                        value = $(this).val();\n\n                        \/\/ Add to settings array\n                        current_settings[ $(this).attr('name') ] = value;\n                    }\n\n                });\n\n                var product_id          = parseInt( $variation_form.data( 'product_id' ) );\n                var all_variations      = $variation_form.data( 'product_variations' )\n\n                \/\/ Fallback to window property if not set - backwards compat\n                if ( ! all_variations )\n                    all_variations = window[ \"product_variations\" ][ product_id ];\n                if ( ! all_variations )\n                    all_variations = window[ \"product_variations\" ];\n                if ( ! all_variations )\n                    all_variations = window[ \"product_variations_\" + product_id ];\n\n                var matching_variations = $.fn.wc_variation_form.find_matching_variations( all_variations, current_settings );\n\n                if ( all_set ) {\n\n                    var variation = matching_variations.shift();\n\n                    if ( variation ) {\n\n                        \/\/ Found - set ID\n                        $variation_form\n                            .find('input[name=variation_id]')\n                            .val( variation.variation_id )\n                            .change();\n\n                        $variation_form.trigger( 'found_variation', [ variation ] );\n\n                    } else {\n\n                        \/\/ Nothing found - reset fields\n                        $variation_form.find('.variations select').val('');\n\n                        if ( ! focus )\n                            $variation_form.trigger( 'reset_image' );\n\n                        alert( woocommerce_params.i18n_no_matching_variations_text );\n\n                    }\n\n                } else {\n\n                    $variation_form.trigger( 'update_variation_values', [ matching_variations ] );\n\n                    if ( ! focus )\n                        $variation_form.trigger( 'reset_image' );\n\n                    if ( ! exclude ) {\n                        $variation_form.find('.single_variation_wrap').slideUp('200');\n                    }\n\n                }\n\n                if ( any_set ) {\n\n                    if ( $reset_variations.css('visibility') == 'hidden' )\n                        $reset_variations.css('visibility','visible').hide().fadeIn();\n\n                } else {\n\n                    $reset_variations.css('visibility','hidden');\n\n                }\n\n            } )\n\n            \/\/ Reset product image\n            .on( 'reset_image', function( event ) {\n\n                var $product        = $(this).closest( '.product' );\n                var $product_img    = $product.find( 'div.images img:eq(0)' );\n                var $product_link   = $product.find( 'div.images a.zoom:eq(0)' );\n                var o_src           = $product_img.attr('data-o_src');\n                var o_title         = $product_img.attr('data-o_title');\n                var o_alt           = $product_img.attr('data-o_alt');\n                var o_href          = $product_link.attr('data-o_href');\n\n                if ( o_src != undefined ) {\n                    $product_img\n                        .attr( 'src', o_src );\n                }\n                if ( o_href != undefined ) {\n                    $product_link\n                        .attr( 'href', o_href );\n                }\n                if ( o_title != undefined ) {\n                    $product_img\n                        .attr( 'title', o_title );\n                    $product_link\n                        .attr( 'title', o_title );\n                }\n                if ( o_alt != undefined ) {\n                     $product_img\n                        .attr( 'alt', o_alt );\n                }\n            } )\n\n            \/\/ Disable option fields that are unavaiable for current set of attributes\n            .on( 'update_variation_values', function( event, variations ) {\n\n                $variation_form = $(this).closest('.variations_form');\n\n                \/\/ Loop through selects and disable\/enable options based on selections\n                $variation_form.find('.variations select').each(function( index, el ) {\n\n                    current_attr_select = $(el);\n\n                    \/\/ Reset options\n                    if ( ! current_attr_select.data( 'attribute_options' ) )\n                        current_attr_select.data( 'attribute_options', current_attr_select.find('option:gt(0)').get() )\n\n                    current_attr_select.find('option:gt(0)').remove();\n                    current_attr_select.append( current_attr_select.data( 'attribute_options' ) );\n                    current_attr_select.find('option:gt(0)').removeClass('active');\n\n                    \/\/ Get name\n                    var current_attr_name   = current_attr_select.attr('name');\n\n                    \/\/ Loop through variations\n                    for ( num in variations ) {\n\n                        if ( typeof( variations[ num ] ) != \"undefined\" ) {\n\n                            var attributes = variations[ num ].attributes;\n\n                            for ( attr_name in attributes ) {\n\n                                var attr_val = attributes[ attr_name ];\n\n                                if ( attr_name == current_attr_name ) {\n\n                                    if ( attr_val ) {\n\n                                        \/\/ Decode entities\n                                        attr_val = $(\"\").html( attr_val ).text();\n\n                                        \/\/ Add slashes\n                                        attr_val = attr_val.replace(\/'\/g, \"\\\\'\");\n                                        attr_val = attr_val.replace(\/\"\/g, \"\\\\\\\"\");\n\n                                        \/\/ Compare the meercat\n                                        current_attr_select.find('option[value=\"' + attr_val + '\"]').addClass('active');\n\n                                    } else {\n\n                                        current_attr_select.find('option:gt(0)').addClass('active');\n\n                                    }\n\n                                }\n\n                            }\n\n                        }\n\n                    }\n\n                    \/\/ Detach inactive\n                    current_attr_select.find('option:gt(0):not(.active)').remove();\n\n                });\n\n                \/\/ Custom event for when variations have been updated\n                $variation_form.trigger('woocommerce_update_variation_values');\n\n            } )\n\n            \/\/ Show single variation details (price, stock, image)\n            .on( 'found_variation', function( event, variation ) {\n                var $variation_form = $(this);\n\n                var $product        = $(this).closest( '.product' );\n                var $product_img    = $product.find( 'div.images img:eq(0)' );\n                var $product_link   = $product.find( 'div.images a.zoom:eq(0)' );\n\n                var o_src           = $product_img.attr('data-o_src');\n                var o_title         = $product_img.attr('data-o_title');\n                var o_alt           = $product_img.attr('data-o_alt');\n                var o_href          = $product_link.attr('data-o_href');\n\n                var variation_image = variation.image_src;\n                var variation_link  = variation.image_link;\n                var variation_title = variation.image_title;\n                var variation_alt   = variation.image_alt;\n\n                $variation_form.find('.variations_button').show();\n                $variation_form.find('.single_variation').html( variation.price_html + variation.availability_html );\n\n                if ( o_src == undefined ) {\n                    o_src = ( ! $product_img.attr('src') ) ? '' : $product_img.attr('src');\n                    $product_img.attr('data-o_src', o_src );\n                }\n\n                if ( o_href == undefined ) {\n                    o_href = ( ! $product_link.attr('href') ) ? '' : $product_link.attr('href');\n                    $product_link.attr('data-o_href', o_href );\n                }\n\n                if ( o_title == undefined ) {\n                    o_title = ( ! $product_img.attr('title') ) ? '' : $product_img.attr('title');\n                    $product_img.attr('data-o_title', o_title );\n                }\n\n                if ( o_alt == undefined ) {\n                    o_alt = ( ! $product_img.attr('alt') ) ? '' : $product_img.attr('alt');\n                    $product_img.attr('data-o_alt', o_alt );\n                }\n\n                if ( variation_image &amp;&amp; variation_image.length &gt; 1 ) {\n                    $product_img\n                        .attr( 'src', variation_image )\n                        .attr( 'alt', variation_alt )\n                        .attr( 'title', variation_title );\n                    $product_link\n                        .attr( 'href', variation_link )\n                        .attr( 'title', variation_title );\n                } else {\n                    $product_img\n                        .attr( 'src', o_src )\n                        .attr( 'alt', o_alt )\n                        .attr( 'title', o_title );\n                    $product_link\n                        .attr( 'href', o_href )\n                        .attr( 'title', o_title );\n                }\n\n                var $single_variation_wrap = $variation_form.find('.single_variation_wrap');\n\n                var $sku        = $product.find('.product_meta').find('.sku');\n                var $weight     = $product.find('.product_weight');\n                var $dimensions = $product.find('.product_dimensions');\n\n                if ( ! $sku.attr( 'data-o_sku' ) )\n                    $sku.attr( 'data-o_sku', $sku.text() );\n\n                if ( ! $weight.attr( 'data-o_weight' ) )\n                    $weight.attr( 'data-o_weight', $weight.text() );\n\n                if ( ! $dimensions.attr( 'data-o_dimensions' ) )\n                    $dimensions.attr( 'data-o_dimensions', $dimensions.text() );\n\n                if ( variation.sku ) {\n                    $sku.text( variation.sku );\n                } else {\n                    $sku.text( $sku.attr( 'data-o_sku' ) );\n                }\n\n                if ( variation.weight ) {\n                    $weight.text( variation.weight );\n                } else {\n                    $weight.text( $weight.attr( 'data-o_weight' ) );\n                }\n\n                if ( variation.dimensions ) {\n                    $dimensions.text( variation.dimensions );\n                } else {\n                    $dimensions.text( $dimensions.attr( 'data-o_dimensions' ) );\n                }\n\n                $single_variation_wrap.find('.quantity').show();\n\n                if ( ! variation.is_in_stock &amp;&amp; ! variation.backorders_allowed ) {\n                    $variation_form.find('.variations_button').hide();\n                }\n\n                if ( variation.min_qty )\n                    $single_variation_wrap.find('input[name=quantity]').attr( 'min', variation.min_qty ).val( variation.min_qty );\n                else\n                    $single_variation_wrap.find('input[name=quantity]').removeAttr('min');\n\n                if ( variation.max_qty )\n                    $single_variation_wrap.find('input[name=quantity]').attr('max', variation.max_qty);\n                else\n                    $single_variation_wrap.find('input[name=quantity]').removeAttr('max');\n\n                if ( variation.is_sold_individually == 'yes' ) {\n                    $single_variation_wrap.find('input[name=quantity]').val('1');\n                    $single_variation_wrap.find('.quantity').hide();\n                }\n\n                $single_variation_wrap.slideDown('200').trigger( 'show_variation', [ variation ] );\n\n            });\n\n    $form.trigger('wc_variation_form');\n    return $form;\n};\n\n$(function() {\n    $('.variations_form').wc_variation_form();\n    $('.variations_form .variations select').change();\n});\n<\/code><\/pre>\n<p>})( jQuery, window, document );<\/p>\n<p>Here is the cart.fragments.js<\/p>\n<pre><code>jQuery(document).ready(function($) {\n\n\/** Cart Handling *\/\n$supports_html5_storage = ( 'sessionStorage' in window &amp;&amp; window['sessionStorage'] !== null );\n\n$fragment_refresh = {\n    url: woocommerce_params.ajax_url,\n    type: 'POST',\n    data: { action: 'woocommerce_get_refreshed_fragments' },\n    success: function( data ) {\n        if ( data &amp;&amp; data.fragments ) {\n\n            $.each( data.fragments, function( key, value ) {\n                $(key).replaceWith(value);\n            });\n\n            if ( $supports_html5_storage ) {\n                sessionStorage.setItem( \"wc_fragments\", JSON.stringify( data.fragments ) );\n                sessionStorage.setItem( \"wc_cart_hash\", data.cart_hash );\n            }\n\n            $('body').trigger( 'wc_fragments_refreshed' );\n        }\n    }\n};\n\nif ( $supports_html5_storage ) {\n\n    $('body').bind( 'added_to_cart', function( event, fragments, cart_hash ) {\n        sessionStorage.setItem( \"wc_fragments\", JSON.stringify( fragments ) );\n        sessionStorage.setItem( \"wc_cart_hash\", cart_hash );\n    });\n\n    try {\n        var wc_fragments = $.parseJSON( sessionStorage.getItem( \"wc_fragments\" ) );\n        var cart_hash    = sessionStorage.getItem( \"wc_cart_hash\" );\n        var cookie_hash  = $.cookie( \"woocommerce_cart_hash\" );\n\n        if ( cart_hash == null || cart_hash == undefined || cart_hash == '' )\n            cart_hash = '';\n\n        if ( cookie_hash == null || cookie_hash == undefined || cookie_hash == '' )\n            cookie_hash = '';\n\n        if ( wc_fragments &amp;&amp; wc_fragments['div.widget_shopping_cart_content'] &amp;&amp; cart_hash == cookie_hash ) {\n\n            $.each( wc_fragments, function( key, value ) {\n                $(key).replaceWith(value);\n            });\n\n            $('body').trigger( 'wc_fragments_loaded' );\n\n        } else {\n            throw \"No fragment\";\n        }\n\n    } catch(err) {\n        $.ajax( $fragment_refresh );\n    }\n\n} else {\n    $.ajax( $fragment_refresh );\n}\n\n\/* Cart hiding *\/\nif ( $.cookie( \"woocommerce_items_in_cart\" ) &gt; 0 )\n    $('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show();\nelse\n    $('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').hide();\n\n$('body').bind( 'adding_to_cart', function() {\n    $('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show();\n} );\n<\/code><\/pre>\n<p>});<\/p>\n<\/li>\n","protected":false},"excerpt":{"rendered":"<p>Dana Bouchard Updated WordPress to newest version and lost our Add to Cart Button. I&#8217;ve been searching everywhere for a solution and tried the ones I have found. We do not have a backup prior to updating unfortunately : \/ These are the errors that show in Chrome developer tools browser when on a page [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3245","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3245"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3245\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}