php - Cart is not Empty Woocommerce Wp jQuery -
i customizing woocommerce wp right , have problem.
how check woocommerce cart using jquery? reason why need want make animations site using jquery when user clicks on product add cart button.
the scenario like: user adds product , site i'm developing gives 1 products, meaning cant buy more (1) product @ time. when user done clicking or buying product , home/product page , clicks add cart button on other product want popup using jquery. problem don't know how it. thank in advance answers.
modify product or home page , add on own button onclick function product id parameter. make ajax call in function .
function somefunction(productid) { $.ajax({ type : "post", url: 'wwww.siteurl.com/wp-admin/admin-ajax.php', data: { action: 'myajax',pid:productid }, success: function(data){ alert(data); // error message user see.use javascript make popup }, error: function(mlhttprequest, textstatus, errorthrown){ alert(errorthrown); } }); } in function.php
function myajax() { $product_id = $_post['pid']; if(wc()->cart->cart_contents_count <1) { wc()->cart->add_to_cart( $product_id ); echo "success"; die(); } else { echo "not more 1 product can added"; // error return jquery function // die(); } } add_action('wp_ajax_myajax', 'myajax'); add_action('wp_ajax_nopriv_myajax', 'myajax'); hope ...
Comments
Post a Comment