Skip to content

Commit

Permalink
Revert "Add display options for cart menu item"
Browse files Browse the repository at this point in the history
This reverts commit a427b26.
  • Loading branch information
razwan committed Dec 18, 2020
1 parent 56686c0 commit 7abee86
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 126 deletions.
44 changes: 20 additions & 24 deletions dist/css/woocommerce/style-rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -1672,34 +1672,30 @@
.cart_list.product_list_widget {
flex-basis: 0; }

.menu-item--cart > a {
text-decoration: none; }

.menu-item--cart:not(.no-icon) > a:before {
content: none !important; }

.menu-item--cart.no-icon .menu-item__icon,
.menu-item--cart.icon-only .menu-item__label {
display: none; }

.menu-item--cart:not(.icon-only) .menu-item__label + .menu-item__icon {
margin-right: 0.75em; }

.menu-item--cart .menu-item__icon {
position: relative;
width: 1.75em;
font-feature-settings: "lnum"; }
.menu-item--cart .menu-item__icon:after {
content: "";
display: block;
.menu-item--cart {
display: flex;
align-items: center; }
.menu-item--cart > a {
border-bottom: 0;
text-decoration: none; }
.menu-item--cart > a:before {
content: none !important; }
.menu-item--cart[class][class][class][class][class] a {
padding: 0;
margin: 0; }
.menu-item--cart[class][class][class][class][class] a:before {
content: none; }
.menu-item--cart .cart-count {
display: flex;
align-items: center;
justify-content: center;
width: 1.75em;
height: 1.75em;
border: .125em solid currentColor;
border-radius: 50%;
position: absolute;
top: 50%;
right: 50%;
transform: translate(50%, -50%); }
font-weight: 700;
line-height: 1;
font-feature-settings: "lnum"; }

#add_payment_method table.cart td.actions .coupon .input-text,
.woocommerce-cart table.cart td.actions .coupon .input-text,
Expand Down
44 changes: 20 additions & 24 deletions dist/css/woocommerce/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1672,34 +1672,30 @@
.cart_list.product_list_widget {
flex-basis: 0; }

.menu-item--cart > a {
text-decoration: none; }

.menu-item--cart:not(.no-icon) > a:before {
content: none !important; }

.menu-item--cart.no-icon .menu-item__icon,
.menu-item--cart.icon-only .menu-item__label {
display: none; }

.menu-item--cart:not(.icon-only) .menu-item__label + .menu-item__icon {
margin-left: 0.75em; }

.menu-item--cart .menu-item__icon {
position: relative;
width: 1.75em;
font-feature-settings: "lnum"; }
.menu-item--cart .menu-item__icon:after {
content: "";
display: block;
.menu-item--cart {
display: flex;
align-items: center; }
.menu-item--cart > a {
border-bottom: 0;
text-decoration: none; }
.menu-item--cart > a:before {
content: none !important; }
.menu-item--cart[class][class][class][class][class] a {
padding: 0;
margin: 0; }
.menu-item--cart[class][class][class][class][class] a:before {
content: none; }
.menu-item--cart .cart-count {
display: flex;
align-items: center;
justify-content: center;
width: 1.75em;
height: 1.75em;
border: .125em solid currentColor;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%); }
font-weight: 700;
line-height: 1;
font-feature-settings: "lnum"; }

#add_payment_method table.cart td.actions .coupon .input-text,
.woocommerce-cart table.cart td.actions .coupon .input-text,
Expand Down
14 changes: 4 additions & 10 deletions dist/js/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,7 @@
enableMinusButton();
});
$(function () {
var $body = $(document.body).not('.woocommerce-cart');
var $cartMenuItem = $('.site-header__menu .menu > .menu-item--cart');
var $cartMenuItemLink = $cartMenuItem.children('a');
var cartMenuItemText = $cartMenuItemLink.text();
var $cartMenuItemCount = $('<span class="menu-item__icon">0</span>');
$cartMenuItemLink.html("<span class=\"menu-item__label\">".concat(cartMenuItemText, " </span>"));
$cartMenuItemCount.appendTo($cartMenuItemLink);
$cartMenuItem.on('click', openMiniCart); // show mini cart when a product is added to cart
var $body = $(document.body).not('.woocommerce-cart'); // show mini cart when a product is added to cart

function onAddedToCart(event, fragments, cart_hash, $button) {
var key = 'div.widget_shopping_cart_content';
Expand Down Expand Up @@ -181,7 +174,7 @@
products += parseInt($quantity.text(), 10);
}); // actually update the cart items count

$cartMenuItem.text(products);
$('.menu-item--cart .cart-count span').text(products);
}
} // show mini cart when Cart menu item is clicked

Expand Down Expand Up @@ -210,7 +203,8 @@

$('.c-mini-cart__overlay, .c-mini-cart__close').on('click', closeMiniCart);
$body.on('added_to_cart', onAddedToCart);
$body.on('added_to_cart removed_from_cart', updateCartMenuItemCount); // in order to avoid template overwrites add the class used to style buttons programatically
$body.on('added_to_cart removed_from_cart', updateCartMenuItemCount);
$('.js-open-cart').on('click', openMiniCart); // in order to avoid template overwrites add the class used to style buttons programatically

$body.on('wc_cart_button_updated', function (event, $button) {
$button.siblings('.added_to_cart').addClass('button');
Expand Down
2 changes: 1 addition & 1 deletion dist/js/woocommerce.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 1 addition & 29 deletions inc/admin/class-admin-nav-menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,7 @@ public function __construct() {
),
);

// $cart_item_count = WC()->cart->get_cart_contents_count();

if ( function_exists( 'WC' ) && pixelgrade_user_has_access( 'woocommerce' ) ) {
$this->menu_items_boxes_config['pxg-extras']['menu_items']['cart'] = array(
'type' => 'custom-pxg',
'type_label' => esc_html__( 'Custom', '__theme_txtd' ),
'title' => esc_html__( 'Cart', '__theme_txtd' ),
'label' => esc_html__( 'Cart', '__theme_txtd' ),
'url' => esc_url( get_permalink( wc_get_page_id( 'cart' ) ) ),
'attr_title' => esc_html__( 'Toggle visibility of cart panel', '__theme_txtd' ),
// These are classes that will be merged with the user defined classes.
'classes' => array( 'menu-item--cart' ),
'custom_fields' => array(
'visual_style' => array(
'type' => 'select',
'label' => esc_html__( 'Visual Style', '__theme_txtd' ),
'description' => esc_html__( 'Choose a visual style suitable to your goals and audience.', '__theme_txtd' ),
'default' => 'icon',
'options' => array(
'label' => esc_html__( 'Label', '__theme_txtd' ),
'icon' => esc_html__( 'Icon', '__theme_txtd' ),
'label_icon' => esc_html__( 'Label with icon', '__theme_txtd' ),
),
),
),
);
}

// Allow others to have a say in this.
// Allow others to have a say in this.
$this->menu_items_boxes_config = apply_filters( 'rosa2_menu_items_boxes_config', $this->menu_items_boxes_config );

/* ===============
Expand Down
29 changes: 29 additions & 0 deletions inc/integrations/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ function rosa2_woocommerce_setup_hooks() {
add_filter( 'woocommerce_product_description_heading', '__return_false', 30 );
add_filter( 'woocommerce_product_additional_information_heading', '__return_false', 30 );

// Append cart to menu
add_filter( 'wp_nav_menu_items', 'rosa2_append_cart_icon_to_menu', 10, 2 );

// Limit related posts number
add_filter( 'woocommerce_output_related_products_args', 'rosa2_limit_related_posts_count', 20 );

Expand Down Expand Up @@ -350,6 +353,32 @@ function rosa2_output_mini_cart() {
<?php }
}


function rosa2_append_cart_icon_to_menu( $items, $args ) {

if ( empty( WC()->cart ) ) {
return $items;
}

$cart_item_count = WC()->cart->get_cart_contents_count();
if ( $cart_item_count ) {
$cart_count_span = '<div class="cart-count"><span>' . esc_html( $cart_item_count ) . '</span></div>';
} else {
/* translators: Zero items in cart. */
$cart_count_span = '<div class="cart-count"><span>' . esc_html__( '0', '__theme_txtd' ) . '</span></div>';
}

$cart_link = '<li class="menu-item menu-item--cart"><a class="js-open-cart" href="' . esc_url( get_permalink( wc_get_page_id( 'cart' ) ) ) . '">' . $cart_count_span . '</a></li>';


// Add the cart link to the end of the menu.
if ( ! empty( $args->theme_location ) && $args->theme_location === 'primary' ) {
$items = $items . $cart_link;
}

return $items;
}

if ( ! function_exists( 'woocommerce_display_categories' ) ) {

function woocommerce_display_categories() {
Expand Down
13 changes: 3 additions & 10 deletions src/js/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@
$(function(){

var $body = $( document.body ).not( '.woocommerce-cart' );
var $cartMenuItem = $( '.site-header__menu .menu > .menu-item--cart' );
var $cartMenuItemLink = $cartMenuItem.children( 'a' );
var cartMenuItemText = $cartMenuItemLink.text();
var $cartMenuItemCount = $( '<span class="menu-item__icon">0</span>' );

$cartMenuItemLink.html( `<span class="menu-item__label">${ cartMenuItemText } </span>` );
$cartMenuItemCount.appendTo( $cartMenuItemLink );

$cartMenuItem.on( 'click', openMiniCart );

// show mini cart when a product is added to cart
function onAddedToCart( event, fragments, cart_hash, $button ) {
Expand Down Expand Up @@ -104,7 +95,7 @@
});

// actually update the cart items count
$cartMenuItem.text( products );
$( '.menu-item--cart .cart-count span' ).text( products );
}
}

Expand Down Expand Up @@ -140,6 +131,8 @@
$body.on( 'added_to_cart', onAddedToCart );
$body.on( 'added_to_cart removed_from_cart', updateCartMenuItemCount );

$( '.js-open-cart' ).on( 'click', openMiniCart );

// in order to avoid template overwrites add the class used to style buttons programatically
$body.on( 'wc_cart_button_updated', function( event, $button ) {
$button.siblings( '.added_to_cart' ).addClass( 'button' );
Expand Down
55 changes: 27 additions & 28 deletions src/scss/woocommerce/pages/_cart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -290,45 +290,44 @@

.menu-item--cart {

display: flex;
align-items: center;

> a {
border-bottom: 0;

text-decoration: none;
}

&:not(.no-icon) > a:before {
content: none !important;
&:before {
content: none !important;
}
}

&.no-icon .menu-item__icon,
&.icon-only .menu-item__label {
display: none;
}
@include specific(5) {
a {
padding: 0;
margin: 0;

&:not(.icon-only) .menu-item__label + .menu-item__icon {
margin-left: 0.75em;
&:before {
content: none;
}
}
}

.menu-item__icon {
position: relative;
width: 1.75em;

font-feature-settings: "lnum";

&:after {
content: "";

display: block;
width: 1.75em;
height: 1.75em;
.cart-count {
display: flex;
align-items: center;
justify-content: center;

border: .125em solid currentColor;
border-radius: 50%;
width: 1.75em;
height: 1.75em;

position: absolute;
top: 50%;
left: 50%;
border: .125em solid currentColor;
border-radius: 50%;

transform: translate(-50%, -50%);
}
font-weight: 700;
line-height: 1;
font-feature-settings: "lnum";
}
}

Expand Down

0 comments on commit 7abee86

Please sign in to comment.