Created
February 5, 2015 15:16
-
-
Save JudeRosario/be10d76cfb28127f48c9 to your computer and use it in GitHub Desktop.
MarketPress Feature : Custom Cart Images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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