This is a useful feature to improve conversions, because you can use cart block as a Call To Action when a customer has added any product to his cart.

Showing an empty cart is not always a good option in most cases (why do you want to do it? and, then, why is the default behavior?)

If this patch is accepted, it will be trivial do it duplicating the views cart block: Provide a Views default argument for the current user's cart ID

CommentFileSizeAuthor
#5 3038346-4.patch2.16 KBdww

Issue fork commerce-3038346

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

calbasi created an issue. See original summary.

MatthijsG’s picture

Second this!

https://www.drupal.org/project/commerce/issues/1275248 #19 is a workaround for version 7.x, but the type in step 4

Set it to Provide default value > Type = Current user's cart order ID

doesn't exist. Not sure which one to use.

demonde’s picture

As a workaroud you can hide the block with css in the MYTHEME.theme file.

function MYTHEME_preprocess_block(&$variables) {
  if ($variables['plugin_id'] == 'commerce_cart') {
    if ($variables['content']['#count'] == 0) {
      $variables['attributes']['class'][] = 'visually-hidden';
    }
  }
}

dww made their first commit to this issue’s fork.

dww’s picture

Version: 8.x-2.12 » 8.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new2.16 KB

I need this. The views-based cart blocks are totally overkill for my project. Here's a patch. MR coming soon.

jsacksick made their first commit to this issue’s fork.

  • jsacksick committed 711a74d0 on 8.x-2.x authored by dww
    Issue #3038346: Option to hide empty cart block
    

  • jsacksick committed 742c8768 on 3.0.x authored by dww
    Issue #3038346: Option to hide empty cart block
    
jsacksick’s picture

Status: Needs review » Fixed

Thanks, merged!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.