Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created June 6, 2024 13:32
Show Gist options
  • Select an option

  • Save nfsarmento/74991fde3a0f061e61527310640b3f4a to your computer and use it in GitHub Desktop.

Select an option

Save nfsarmento/74991fde3a0f061e61527310640b3f4a to your computer and use it in GitHub Desktop.

Revisions

  1. nfsarmento created this gist Jun 6, 2024.
    37 changes: 37 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    <?php

    /**
    *
    * Create Shortcode for WooCommerce Basket Item and WooCommerce Account Item
    * @link https://wpbeaches.com/add-woocommerce-cart-icon-to-menu-with-cart-item-count/#just-icon
    */
    function mic_woo_cart_but() {
    ob_start();
    $cart_count = WC()->cart->cart_contents_count; // Set variable for cart item count
    $cart_total = WC()->cart->get_cart_total();
    $cart_url = wc_get_cart_url(); // Set Cart URL
    ?>

    <div class="menu-icons-mic">

    <?php
    if ( $cart_count > 0 ) {
    ?>
    <a href="<?php echo esc_attr( $cart_url ); ?>" title="My Basket">
    <img width="32" height="32" class="header-icon-basket" src="<?php echo esc_html( get_stylesheet_directory_uri() ); ?>/assets/img/basket-full.png" alt="Shop">
    </a>

    <?php } ?>

    <a href="/my-account/" title="My Account">
    <img width="20" height="20" class="header-icon-account" src="<?php echo esc_html( get_stylesheet_directory_uri() ); ?>/assets/img/account-icon.svg" alt="My Account" style="margin-top: 2px;">
    </a>

    </div>

    <?php
    return ob_get_clean();
    }
    // @codingStandardsIgnoreStart
    add_shortcode ('woo_cart_and_account', 'mic_woo_cart_but' );
    // @codingStandardsIgnoreEnd