I've got some code (below) that shows a notification next to my wishlist icon on the header, which shows the number of items within the wishlist. Its a great tool to add to this amazing plugin. But, I cannot figure out how to remove the notification/ticker when the wishlist is empty. Thoughts?
The code I posted before is a revision of the following code. The following code successfully shows the woosw header icon and the notification with a woosw product count. I've been trying to modify the following code to hide the notification if the woosw product count is equal to zero. The code I posted before is what I presumed would have been the winner for all my attempts, but it just hides the entire output, icon and all, regardless of the woosw product count.
Hello!
I've got some code (below) that shows a notification next to my wishlist icon on the header, which shows the number of items within the wishlist. Its a great tool to add to this amazing plugin. But, I cannot figure out how to remove the notification/ticker when the wishlist is empty. Thoughts?
Here's that code:
"
add_action('electro_header_icons', 'woosw_header_icons', 60);
function woosw_header_icons()
{
if (class_exists('WPCleverWoosw')) {
$wishlist_count = WPCleverWoosw::get_count();
?>
<div class="header-icon" data-toggle="tooltip" data-placement="bottom"
data-title="<?php echo esc_attr(esc_html__('Wishlist', 'electro')); ?>">
<div class="woosw-menu-item">
<a href="<?php echo esc_url(WPCleverWoosw::get_url()); ?>">
<span class="woosw-menu-item-inner"
data-count="<?php echo esc_attr($wishlist_count); ?>">
Wishlist
<?php if ($wishlist_count > 0) : ?>
<span class="notification-count" id="wishlist-notification-<?php echo esc_attr($wishlist_count); ?>"><?php echo esc_html($wishlist_count); ?></span>
<?php endif; ?>
</span>
</a>
</div>
</div>
<script>
<?php if ($wishlist_count === 0) : ?>
document.addEventListener("DOMContentLoaded", function () {
var notificationElement = document.getElementById('wishlist-notification-<?php echo esc_attr($wishlist_count); ?>');
if (notificationElement) {
notificationElement.style.display = 'none';
}
});
<?php endif; ?>
</script>
<?php
}
}
"
Thanks for your time, and thanks for the work on this awesome plugin!
Jon
theopenmarket.co
Ah, sorry, I forgot a bit more information.
The code I posted before is a revision of the following code. The following code successfully shows the woosw header icon and the notification with a woosw product count. I've been trying to modify the following code to hide the notification if the woosw product count is equal to zero. The code I posted before is what I presumed would have been the winner for all my attempts, but it just hides the entire output, icon and all, regardless of the woosw product count.
Thanks again!
add_action( 'electro_header_icons', 'woosw_header_icons', 60 );
function woosw_header_icons() {
if ( class_exists( 'WPCleverWoosw' ) ) { ?>
<div class="header-icon" data-toggle="tooltip" data-placement="bottom"
data-title="<?php echo esc_attr( esc_html__( 'Wishlist', 'electro' ) ); ?>">
<div class="woosw-menu-item">
<a href="<?php echo esc_url( WPCleverWoosw::get_url() ); ?>">
<span class="woosw-menu-item-inner"
data-count="<?php echo esc_attr( WPCleverWoosw::get_count() ); ?>">Wishlist</span>
</a>
</div>
</div>
<?php }
}
add_filter( 'electro_handheld_header_links', 'woosw_handheld_header_links', 10 );
function woosw_handheld_header_links( $links ) {
$links['woosw-menu-item'] = array(
'priority' => 10,
'callback' => 'woosw_handheld_header_links_icon',
);
$links = woocommerce_sort_product_tabs( $links );
return $links;
}
function woosw_handheld_header_links_icon() {
if ( class_exists( 'WPCleverWoosw' ) ) { ?>
<a href="<?php echo esc_url( WPCleverWoosw::get_url() ); ?>">
<span class="woosw-menu-item-inner" data-count="<?php echo esc_attr( WPCleverWoosw::get_count() ); ?>">Wishlist</span>
</a>
<?php }
}
Hi Jon,
Thanks for contacting WPClever Support Forum. We're not available at the weekends so today (Monday) I am able to process your ticket.
We’ve received your ticket and assigned one of our developers to help you with that.
He’ll be looking into your question and responding with specific instructions as soon as possible.
Please stay patient as we're having very heavy workloads, it might take some time for our developers to reach back.
Best regards.
Janilyn T. - WPClever Support Agent
Hi Jon,
To hide the zero count, you can use the CSS code:
Best regards,
Dustin
Oof da! I way overshot that. Thanks!