Skip to main content

If you wish to change the Cart icon in the top header within Dante, you can do so by adding the two functions below in the child theme’s ‘functions.php’ file and changing the class names as we have replaced ‘ss-cart’ to ‘ss-mug’ so a mug icon appears instead of the cart one in the below example.

<?php

/* CART DROPDOWN
================================================== */
if (!function_exists('sf_get_cart')) {
function sf_get_cart() {

$cart_output = "";

// Check if WooCommerce is active
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {

global $woocommerce;

$cart_total = $woocommerce->cart->get_cart_total();
$cart_count = $woocommerce->cart->cart_contents_count;
$cart_count_text = sf_product_items_text($cart_count);

$cart_output .= '<li class="parent shopping-bag-item"><a class="cart-contents" href="'.$woocommerce->cart->get_cart_url().'" title="'.__("View your shopping cart", "swiftframework").'"><i class="ss-mug"></i>'.$cart_total.'</a>';
$cart_output .= '<ul class="sub-menu">';
$cart_output .= '<li>';
$cart_output .= '<div class="shopping-bag">';

if ( $cart_count != "0" ) {

$cart_output .= '<div class="bag-header">'.$cart_count_text.' '.__('in the shopping bag', 'swiftframework').'</div>';

$cart_output .= '<div class="bag-contents">';

foreach ($woocommerce->cart->cart_contents as $cart_item_key => $cart_item) {

$bag_product = $cart_item['data'];
$product_title = $bag_product->get_title();
$product_short_title = (strlen($product_title) > 25) ? substr($product_title, 0, 22) . '...' : $product_title;

if ($bag_product->exists() && $cart_item['quantity']>0) {
$cart_output .= '<div class="bag-product clearfix">';
$cart_output .= '<figure><a class="bag-product-img" href="'.get_permalink($cart_item['product_id']).'">'.$bag_product->get_image().'</a></figure>';
$cart_output .= '<div class="bag-product-details">';
$cart_output .= '<div class="bag-product-title"><a href="'.get_permalink($cart_item['product_id']).'">' . apply_filters('woocommerce_cart_widget_product_title', $product_short_title, $bag_product) . '</a></div>';
$cart_output .= '<div class="bag-product-price">'.__("Unit Price:", "swiftframework").'
'.woocommerce_price($bag_product->get_price()).'</div>';
$cart_output .= '<div class="bag-product-quantity">'.__('Quantity:', 'swiftframework').' '.$cart_item['quantity'].'</div>';
$cart_output .= '</div>';
$cart_output .= apply_filters( 'woocommerce_cart_item_remove_link', sprintf('<a href="%s" class="remove" title="%s">&times;</a>', esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ), __('Remove this item', 'woocommerce') ), $cart_item_key );

$cart_output .= '</div>';
}
}

$cart_output .= '</div>';

$cart_output .= '<div class="bag-buttons">';

$cart_output .= '<a class="sf-button standard sf-icon-reveal bag-button" href="'.esc_url( $woocommerce->cart->get_cart_url() ).'"><i class="ss-view"></i><span class="text">'. __('View shopping bag', 'swiftframework').'</span></a>';

$cart_output .= '<a class="sf-button standard sf-icon-reveal checkout-button" href="'. esc_url( $woocommerce->cart->get_checkout_url() ).'"><i class="ss-creditcard"></i><span class="text">'.__('Proceed to checkout', 'swiftframework').'</span></a>';

$cart_output .= '</div>';

} else {

$cart_output .= '<div class="bag-header">'.__("0 items in the shopping bag", "swiftframework").'</div>';

$cart_output .= '<div class="bag-empty">'.__('Unfortunately, your shopping bag is empty.','swiftframework').'</div>';

$shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );

$cart_output .= '<div class="bag-buttons">';

$cart_output .= '<a class="sf-button standard sf-icon-reveal shop-button" href="'.esc_url( $shop_page_url ).'"><i class="ss-mug"></i><span class="text">'.__('Go to the shop', 'swiftframework').'</span></a>';

$cart_output .= '</div>';

}

$cart_output .= '</div>';
$cart_output .= '</li>';
$cart_output .= '</ul>';
$cart_output .= '</li>';

}

return $cart_output;
}
}

/* ADD TO CART HEADER RELOAD
================================================== */
if (!function_exists('sf_woo_header_add_to_cart_fragment')) {
function sf_woo_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;

ob_start();

$cart_count = $woocommerce->cart->cart_contents_count;
$cart_count_text = sf_product_items_text($cart_count);

?>

<li class="parent shopping-bag-item">
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'swiftframework'); ?>"><i class="ss-mug"></i><?php echo $woocommerce->cart->get_cart_total(); ?></a>

<ul class="sub-menu">
<li>
<div class="shopping-bag">

<?php if ( $cart_count != "0" ) { ?>

<div class="bag-header"><?php echo $cart_count_text; ?> <?php _e('in the shopping bag', 'swiftframework'); ?></div>

<div class="bag-contents">

<?php foreach ($woocommerce->cart->cart_contents as $cart_item_key => $cart_item) { ?>

<?php
$bag_product = $cart_item['data'];
$product_title = $bag_product->get_title();
?>

<?php if ($bag_product->exists() && $cart_item['quantity']>0) { ?>

<div class="bag-product clearfix">

<figure><a class="bag-product-img" href="<?php echo get_permalink($cart_item['product_id']); ?>"><?php echo $bag_product->get_image(); ?></a></figure>

<div class="bag-product-details">
<div class="bag-product-title">
<a href="<?php echo get_permalink($cart_item['product_id']); ?>">
<?php echo apply_filters('woocommerce_cart_widget_product_title', $product_title, $bag_product); ?></a>
</div>
<div class="bag-product-price"><?php _e("Unit Price:", "swiftframework"); ?> <?php echo woocommerce_price($bag_product->get_price()); ?></div>
<div class="bag-product-quantity"><?php _e('Quantity:', 'swiftframework'); ?> <?php echo $cart_item['quantity']; ?></div>
</div>

<?php echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf('<a href="%s" class="remove" title="%s">&times;</a>', esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ), __('Remove this item', 'woocommerce') ), $cart_item_key ); ?>

</div>

<?php } ?>

<?php } ?>

</div>

<div class="bag-buttons">

<a class="sf-button standard sf-icon-reveal bag-button" href="<?php echo esc_url( $woocommerce->cart->get_cart_url() ); ?>"><i class="ss-view"></i><span class="text"><?php _e('View shopping bag', 'swiftframework'); ?></span></a>

<a class="sf-button standard sf-icon-reveal checkout-button" href="<?php echo esc_url( $woocommerce->cart->get_checkout_url() ); ?>"><i class="ss-creditcard"></i><span class="text"><?php _e('Proceed to checkout', 'swiftframework'); ?></span></a>

</div>

<?php } else { ?>

<div class="bag-header"><?php _e("0 items in the shopping bag", "swiftframework"); ?></div>

<div class="bag-empty"><?php _e('Unfortunately, your shopping bag is empty.','swiftframework'); ?></div>

<div class="bag-buttons">

<?php $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) ); ?>

<a class="sf-button standard sf-icon-reveal checkout-button" href="<?php echo esc_url( $shop_page_url ); ?>"><i class="ss-mug"></i><span class="text"><?php _e('Go to the shop', 'swiftframework'); ?></span></a>

</div>

<?php } ?>

</div>
</li>
</ul>
</li>

<?php

$fragments['.shopping-bag-item'] = ob_get_clean();

return $fragments;

}
add_filter('add_to_cart_fragments', 'sf_woo_header_add_to_cart_fragment');
}

?>

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.