bluemask11
Programmer
Hi!
I'm struggling for a few days to solve a problem. I have a floating cart plugin from MarketPress, it's a free plugin, I want to make it hide when it's empty but it doesn't work.
I've added an if statement where the code is underlined but it doesn't work. Can you help me please?
Cheers,
Nelutu
here is the code
I'm struggling for a few days to solve a problem. I have a floating cart plugin from MarketPress, it's a free plugin, I want to make it hide when it's empty but it doesn't work.
I've added an if statement where the code is underlined but it doesn't work. Can you help me please?
Cheers,
Nelutu
here is the code
JavaScript:
<!-- Load JS -->
<script type="text/javascript">
jQuery(document).ready(function () {
// floating cart
jQuery(document).ajaxComplete(function(e, xhr, settings) {
var tot = 0;
var cart_tot = 0;
<?php if ( $showcartitem == 'yes' ) { ?>
jQuery.each(jQuery('#cart-section td.mp_cart_col_quant'),function(){
var qty = jQuery(this).html() - 0;
if(!isNaN(qty)){
tot += qty;
}
});
jQuery('.floating-cart span.cart-total-items').html(tot);
if (tot <=0){
$(".floating-cart").hide();
}
<?php } ?>
<?php if ( $showcartamount == 'yes' ) { ?>
jQuery.each(jQuery('#cart-section td.mp_cart_col_total'),function(){
cart_tot = jQuery(this).html();
});
jQuery('.floating-cart span.cart-total-amount').html(cart_tot);
<?php } ?>
});
});
</script>
<?php
}
}
function floating_cart_contents_in_button( $echo = true , $settings = '' ){
$showbtntext = esc_attr($settings['fcsettings_general_show_button_text']);
$buttontext = esc_attr($settings['fcsettings_general_button_text']);
$showcartitem = esc_attr($settings['fcsettings_general_show_cart_total_item']);
$showcartamount = esc_attr($settings['fcsettings_general_show_cart_total_amount']);
$output = '';
if ( $showcartitem == 'yes' )
$output .= '<span class="cart-total-items">'.mp_items_count_in_cart().'</span>'.__( ' item(s)' , 'floating-cart' );
if ( $showcartitem == 'yes' && $showcartamount == 'yes' )
$output .= ' - ';
if ( $showcartamount == 'yes' )
$output .= '<span class="cart-total-amount">'.$this->floating_cart_total_amount_in_cart( false ).'</span>';
if ( $showbtntext == 'yes' )
$output .= '<span class="view-cart"> - '.__( $buttontext, 'floating-cart' ).'</span>';
if ($echo) {
echo $output;
} else {
return $output;
}
}
function floating_cart_total_amount_in_cart( $echo = true ) {
global $mp, $blog_id;
$blog_id = (is_multisite()) ? $blog_id : 1;
$current_blog_id = $blog_id;
$global_cart = $mp->get_cart_contents(true);
if (!$mp->global_cart) //get subset if needed
$selected_cart[$blog_id] = $global_cart[$blog_id];
else
$selected_cart = $global_cart;
$totals = array();
if ( !empty($selected_cart)) {
foreach ($selected_cart as $bid => $cart) {
if (is_multisite())
switch_to_blog($bid);
if (!empty($cart)) {
foreach ($cart as $product_id => $variations) {
foreach ($variations as $variation => $data) {
$totals[] = $data['price'] * $data['quantity'];
}
}
}
}
}
if (is_multisite())
switch_to_blog($current_blog_id);
$total = array_sum($totals);
if ($echo) {
echo $mp->format_currency('', $total);
} else {
return $mp->format_currency('', $total);
}
}
function floating_cart_plugin_updater_init() {
include_once( $this->plugin_path .'inc/fc-updater.php' );
if ( ! defined( 'WP_GITHUB_FORCE_UPDATE' ) ) {
define( 'WP_GITHUB_FORCE_UPDATE', true );
}
if ( is_admin() ) {
$config = array(
'slug' => plugin_basename( __FILE__ ),
'proper_folder_name' => 'mp-floating-cart',
'api_url' => '[URL unfurl="true"]https://api.github.com/repos/nathanonn/mp-floating-cart',[/URL]
'raw_url' => '[URL unfurl="true"]https://raw.github.com/nathanonn/mp-floating-cart/master',[/URL]
'github_url' => '[URL unfurl="true"]https://github.com/nathanonn/mp-floating-cart',[/URL]
'zip_url' => '[URL unfurl="true"]https://github.com/nathanonn/mp-floating-cart/zipball/master',[/URL]
'sslverify' => true,
'requires' => '3.5',
'tested' => '3.5.1',
'readme' => 'README.md',
'access_token' => '',
);
new WP_GitHub_Updater( $config );
}
}
}
new MPFloatingCart();
?>