{"action":"created","issue":{"url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads/issues/4653","repository_url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads","labels_url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads/issues/4653/labels{/name}","comments_url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads/issues/4653/comments","events_url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads/issues/4653/events","html_url":"https://github.com/easydigitaldownloads/easy-digital-downloads/issues/4653","id":158270373,"number":4653,"title":"Adding display:none to price options breaks add to cart jQuery","user":{"login":"pippinsplugins","id":1034109,"avatar_url":"https://avatars.githubusercontent.com/u/1034109?v=3","gravatar_id":"","url":"https://api.github.com/users/pippinsplugins","html_url":"https://github.com/pippinsplugins","followers_url":"https://api.github.com/users/pippinsplugins/followers","following_url":"https://api.github.com/users/pippinsplugins/following{/other_user}","gists_url":"https://api.github.com/users/pippinsplugins/gists{/gist_id}","starred_url":"https://api.github.com/users/pippinsplugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pippinsplugins/subscriptions","organizations_url":"https://api.github.com/users/pippinsplugins/orgs","repos_url":"https://api.github.com/users/pippinsplugins/repos","events_url":"https://api.github.com/users/pippinsplugins/events{/privacy}","received_events_url":"https://api.github.com/users/pippinsplugins/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads/labels/Bug","name":"Bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads/milestones/109","html_url":"https://github.com/easydigitaldownloads/easy-digital-downloads/milestones/2.7","labels_url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads/milestones/109/labels","id":1259726,"number":109,"title":"2.7","description":null,"creator":{"login":"pippinsplugins","id":1034109,"avatar_url":"https://avatars.githubusercontent.com/u/1034109?v=3","gravatar_id":"","url":"https://api.github.com/users/pippinsplugins","html_url":"https://github.com/pippinsplugins","followers_url":"https://api.github.com/users/pippinsplugins/followers","following_url":"https://api.github.com/users/pippinsplugins/following{/other_user}","gists_url":"https://api.github.com/users/pippinsplugins/gists{/gist_id}","starred_url":"https://api.github.com/users/pippinsplugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pippinsplugins/subscriptions","organizations_url":"https://api.github.com/users/pippinsplugins/orgs","repos_url":"https://api.github.com/users/pippinsplugins/repos","events_url":"https://api.github.com/users/pippinsplugins/events{/privacy}","received_events_url":"https://api.github.com/users/pippinsplugins/received_events","type":"User","site_admin":false},"open_issues":102,"closed_issues":1,"state":"open","created_at":"2015-08-18T02:24:40Z","updated_at":"2016-06-03T00:51:46Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2016-06-03T00:51:46Z","updated_at":"2016-06-03T15:58:18Z","closed_at":null,"body":"Alright, this is one of the stranger bugs I've seen.\r\n\r\nLet's say you have a download product with 5 price options, like this:\r\n![screen shot 2016-06-02 at 7 45 37 pm](https://cloud.githubusercontent.com/assets/1034109/15765454/a235cd86-28fa-11e6-9277-8e62d551f829.png)\r\n\r\nNow, for one reason or another, you decide that you want to hide the last two price options using CSS:\r\n```css\r\n.edd_price_options ul li:nth-child(4), .edd_price_options ul li:nth-child(5), .edd_price_options ul li:nth-child(6) {\r\n\tdisplay: none;\r\n}\r\n```\r\nThis results in the price options rendering like this:\r\n![screen shot 2016-06-02 at 7 46 50 pm](https://cloud.githubusercontent.com/assets/1034109/15765472/c4da8bba-28fa-11e6-9975-e714931baf71.png)\r\n\r\nSo far so good.\r\n\r\nNow a customer comes along and selects `Price Three` and clicks add to cart. The cart widget and checkout now show that you have actually added `Price One` to the cart:\r\n\r\n![screen shot 2016-06-02 at 7 48 03 pm](https://cloud.githubusercontent.com/assets/1034109/15765487/f0c76ebe-28fa-11e6-97b9-b2c209229f0e.png)\r\n\r\nIt does not matter which price option is selected, the first price option will _always_ be added to the cart so long as the CSS above is on the site.\r\n\r\nNow, if that CSS is changed to this, it works fine:\r\n```css\r\n.edd_price_options ul li:nth-child(4), .edd_price_options ul li:nth-child(5), .edd_price_options ul li:nth-child(6) {\r\n\theight: 0;\r\n\twidth: 0;\r\n\toverflow: hidden;\r\n}\r\n```\r\nThis CSS also works:\r\n```css\r\n.edd_price_options ul li:nth-child(4), .edd_price_options ul li:nth-child(5), .edd_price_options ul li:nth-child(6) {\r\n\tvisibility: hidden;\r\n}\r\n```\r\n\r\nThe JS that handles the add to cart process is in `edd-ajax.js`. Here's the relevant section:\r\n```js\r\nif( variable_price == 'yes' ) {\r\n\r\n\tif ( form.find('.edd_price_option_' + download).is('input:hidden') ) {\r\n\t\titem_price_ids[0] = $('.edd_price_option_' + download, form).val();\r\n\t\tif ( form.find('.edd-submit').data('price') && form.find('.edd-submit').data('price') > 0 ) {\r\n\t\t\tfree_items = false;\r\n\t\t}\r\n\t} else {\r\n\t\tif( ! form.find('.edd_price_option_' + download + ':checked', form).length ) {\r\n\t\t\t // hide the spinner\r\n\t\t\t$this.removeAttr( 'data-edd-loading' );\r\n\t\t\talert( edd_scripts.select_option );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tform.find('.edd_price_option_' + download + ':checked', form).each(function( index ) {\r\n\t\t\titem_price_ids[ index ] = $(this).val();\r\n\r\n\t\t\t// If we're still only at free items, check if this one is free also\r\n\t\t\tif ( true === free_items ) {\r\n\t\t\t\tvar item_price = $(this).data('price');\r\n\t\t\t\tif ( item_price && item_price > 0 ) {\r\n\t\t\t\t\t// We now have a paid item, we can't use add_to_cart\r\n\t\t\t\t\tfree_items = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t});\r\n\t}\r\n\r\n}\r\n```\r\n\r\nIt appears that the `display:none` is effecting jQuery's ability to return proper results with `.find()`, but I have no idea why.\r\n"},"comment":{"url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads/issues/comments/223618958","html_url":"https://github.com/easydigitaldownloads/easy-digital-downloads/issues/4653#issuecomment-223618958","issue_url":"https://api.github.com/repos/easydigitaldownloads/easy-digital-downloads/issues/4653","id":223618958,"user":{"login":"pippinsplugins","id":1034109,"avatar_url":"https://avatars.githubusercontent.com/u/1034109?v=3","gravatar_id":"","url":"https://api.github.com/users/pippinsplugins","html_url":"https://github.com/pippinsplugins","followers_url":"https://api.github.com/users/pippinsplugins/followers","following_url":"https://api.github.com/users/pippinsplugins/following{/other_user}","gists_url":"https://api.github.com/users/pippinsplugins/gists{/gist_id}","starred_url":"https://api.github.com/users/pippinsplugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pippinsplugins/subscriptions","organizations_url":"https://api.github.com/users/pippinsplugins/orgs","repos_url":"https://api.github.com/users/pippinsplugins/repos","events_url":"https://api.github.com/users/pippinsplugins/events{/privacy}","received_events_url":"https://api.github.com/users/pippinsplugins/received_events","type":"User","site_admin":false},"created_at":"2016-06-03T15:58:18Z","updated_at":"2016-06-03T15:58:18Z","body":"Moving this up in priority."}}
{"actor":{"display_login":"pippinsplugins"}}