Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Created February 5, 2015 15:16
Show Gist options
  • Save JudeRosario/be10d76cfb28127f48c9 to your computer and use it in GitHub Desktop.
Save JudeRosario/be10d76cfb28127f48c9 to your computer and use it in GitHub Desktop.
MarketPress Feature : Custom Cart Images
add_action( 'wp_ajax_check_empty', 'is_cart_empty' );
add_action( 'wp_ajax_nopriv_check_empty', 'is_cart_empty' );
add_action( 'wp_footer', 'wagon_script' );
function is_cart_empty($content) {
global $mp ;
$products = $mp -> get_cart_contents() ;
if (empty($products))
echo "Empty" ;
else
echo "Full" ;
wp_die();
}
function wagon_script(){
?>
<script>
function update_wagon_image() {
jQuery.ajax({
type: 'POST',
url: MP_Ajax.ajaxUrl,
global: false,
data: { action: 'check_empty'},
success: function(data) {
if("Empty" == data) {
jQuery('.wagon a img')
.attr('src', 'someimage.png') ;
}
if("Full" == data)
{
jQuery('.wagon a img')
.attr('src', 'someotherimage.png') ;
}
}
});
}
jQuery( document ).bind('ready ajaxStop', update_wagon_image );
</script>
<?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment