Jump to content

Adding button throughout the website?

Recommended Posts

46 minutes ago, CCE said:

Site URL: https://cliftoncreativeevents.com

I have multiple shop pages but I don't want anyone to be able to purchase anything directly. So I hid the add to cart button and want to add a contact button which links to the form page. But is there a way to have that button pop up on all product pages without having to individually add it in?

What is the site wide password

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

Please see Add Button After Add to Cart Button of Product Detail Page.

Let us know how it goes.

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
14 minutes ago, creedon said:

Add the following to Settings > Advanced > Code Injection > HEADER.


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Add the following to Store Settings > Advanced > Page Header Code Injection for the store page.


<script>

  $( ( ) => {
  
    /*
    
      add button after add to cart button of product detail page
      
      SS Versions : 7.0, 7.1
      
      */
      
    const text = 'View Shopping Bag';
    
    const url = '/cart';
    
    const targetAtttributeValue = ''; /* use _self (default, if left empty) |
                                         _blank | _parent | _top | framename */
    
    // do not change anything below, there be the borg here
    
    const $addToCartButton = $( '.sqs-add-to-cart-button-wrapper' );
    
    if ( ! $addToCartButton.length ) return;
    
    const buttonSelector = '.sqs-add-to-cart-button';
    
    let $additionalCartButton = $addToCartButton
    
      .clone ( )
      
      .removeAttr ( 'id' );
      
    let $e = $( buttonSelector, $additionalCartButton )
    
      .attr ( 'href', url )
      
      .removeAttr ( 'id ' +
      
        'data-collection-id ' +
        
        'data-item-id ' +
        
        'data-original-label ' +
        
        'data-product-type ' +
        
        'data-use-custom-label' )
        
      .find ( '.sqs-add-to-cart-button-inner' )
      
        .html ( text )
        
        .end ( );
        
    if ( targetAtttributeValue )
    
      $e.attr ( 'target', targetAtttributeValue );
      
    let $anchorTag = $( '<a>' );
    
    $.each ( $e.prop ( 'attributes' ), function ( ) {
    
      $anchorTag.attr ( this.name, this.value );
      
      } );
      
    $e
    
      .children ( )
      
      .appendTo ( $anchorTag );
      
    $e.replaceWith ( $anchorTag )
    
    $additionalCartButton.insertAfter ( $addToCartButton );
    
    } );
    
  </script>

This is for v7.0 and v7.1.

Let us know how it goes.

I put it in, it works great but it only works when I remove the code I put in to hide the add to cart and quantity options. Once I put my code back in, it also removes the new button. 

 

.product-quantity-input {
 display:none !important;
}

.sqs-add-to-cart-button-wrapper, {
 display:none !important;
}

 

Link to comment
  • 1 month later...

I have updated my code post. If your current code is working then no need to update. The new feature is support for a guard processor. This means you can write a custom script that can help decide if the code to add the button should run. Useful if you want the code to only run on certain pages. For example if your product has a certain tag or if the product has a particular sku. It's really up to you! 😀

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 1 year later...
4 hours ago, prustique said:

I was wondering if there was any way to style the second button separately from the add to cart one?

Please post the URL for a page on your site where we can see your issue.

If your site is not public please set up a site-wide password, if you've not already done so.

Post the password here.

Adding a site-wide password does not allow anyone to alter your site. It only allows those with the password to see your site. Please read the documentation at the link provided to understand how it works.

Please read the documentation at the link provided on how to share a link to your site to understand how it works. A link to the backend of the your site won’t work for us, i.e. a url that contains /config/.

We can then take a look at your issue.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
On 9/20/2022 at 5:34 AM, prustique said:

I was wondering if there was any way to style the second button separately from the add to cart one?

This isn't a solution but starter code.

.sqs-add-to-cart-button-wrapper:last-child .sqs-add-to-cart-button {

  background-color : red !important;
  
  }

The trick here is the last-child pseudo-classes selector.

Let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 3 months later...

Hello Creedon,

The secondary button under the add to cart button is working perfectly, but I just want to hide the original add to cart button from all product pages. Please, if you can, assist me.

See the attached screenshot. 

Looking forward to hearing from you shortly. 

Thanks, Umair

Web capture_30-12-2022_115929_www.araind.com.jpg

Link to comment
9 minutes ago, Umair786 said:

I just want to hide the original add to cart button from all product pages.

Please post the URL for a page on your site where we can see your issue.

A link to the backend of the your site won’t work for us, i.e. a url that contains /config/.

Please set up a site-wide password, if your site is not public and you've not already done so.

Post the password here.

Adding a site-wide password does not allow anyone to alter your site. It only allows those with the password to see your site.

Please read the site-wide password and how to share a link documentation to understand how they work.

We can then take a look at your issue.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
13 hours ago, Umair786 said:

The secondary button under the add to cart button is working perfectly, but I just want to hide the original add to cart button from all product pages.

The duping code was meant for situations where you want two buttons.

Instead of duplicating the button you may want to use the following code.

 

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.