Am I correct in thinking this should work?
I have this jquery:
<script>
$(function() {
$(".wpsc_buy_button").click(function(evt) {
$(".counter").load("index.php")
evt.preventDefault();
})
})
</script>
This .span:
<span class="counter">
<?php
$i = 0;
while(wpsc_have_cart_items()): wpsc_the_cart_item();
?>
<?php $i += wpsc_cart_item_quantity(); ?>
<?php endwhile; ?>
<?php print $i ?>
</span>
And this button:
<input type="submit" value="Add To Cart" name="Buy" class="wpsc_buy_button" id="product_16_submit_button"/>
You can change the code to work this way:
<script>
$(function() {
$(".wpsc_buy_button").click(function(evt) {
$.get("index.php", function(){
var current = parseInt($.trim($(".counter").text()));
$(".counter").text(current+1);
});
evt.preventDefault();
})
})
</script>
UPDATED
You're doing it the hard way. Here is the way you should do it: Locate the file http://tobyclothing.com/wp-content/plugins/wp-e-commerce/wpsc-core/js/wp-e-commerce.js?ver=3.8.7.6.2.494864 and find these lines: (line 248 - 257)
jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
eval(returned_data);
jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');
if(jQuery('#fancy_notification') != null) {
jQuery('#loading_animation').css("display", 'none');
//jQuery('#fancy_notificationimage').css("display", 'none');
}
// add your NEW_CODE here
});
your NEW_CODE will be:
var current = parseInt($.trim($(".counter").text()));
$(".counter").text(current+1);
which will then result in:
jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
eval(returned_data);
jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');
if(jQuery('#fancy_notification') != null) {
jQuery('#loading_animation').css("display", 'none');
//jQuery('#fancy_notificationimage').css("display", 'none');
}
var current = parseInt($.trim($(".counter").text()));
$(".counter").text(current+1);
});
UPDATE 2
If the user enters any number of quatity
var qty = parseInt(jQuery("input[name='wpsc_quantity_update']").val());
jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
eval(returned_data);
jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');
if(jQuery('#fancy_notification') != null) {
jQuery('#loading_animation').css("display", 'none');
//jQuery('#fancy_notificationimage').css("display", 'none');
}
var current = parseInt(jQuery.trim(jQuery(".counter").text()));
jQuery(".counter").text(current+qty);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.