/    Sign up×
Community /Pin to ProfileBookmark

Hide div class if total equal to 0

Hello!

I’m struggling for a few days to solve a problem. I have a plugin for a floating cart 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,

here is the code

[CODE]<!– 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){
jQuery(‘.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’ => ‘https://api.github.com/repos/nathanonn/mp-floating-cart’,
‘raw_url’ => ‘https://raw.github.com/nathanonn/mp-floating-cart/master’,
‘github_url’ => ‘https://github.com/nathanonn/mp-floating-cart’,
‘zip_url’ => ‘https://github.com/nathanonn/mp-floating-cart/zipball/master’,
‘sslverify’ => true,
‘requires’ => ‘3.5’,
‘tested’ => ‘3.5.1’,
‘readme’ => ‘README.md’,
‘access_token’ => ”,
);

new WP_GitHub_Updater( $config );

}
}

}

new MPFloatingCart();

?>[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @bluemask11 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...