javascript - Woocommerce "Add to cart" ajax -


on product category page, when clicks "add cart", woocommerce adds "view cart" below button through ajax. found script handle /assets/js/frontend/add-to-cart.js

now, want add "procceed checkout", can go checkout immediately.

this output of script:

jquery( function( $ ) {  // wc_add_to_cart_params required continue, ensure object exists if ( typeof wc_add_to_cart_params === 'undefined' )     return false;  // ajax add cart $( document ).on( 'click', '.add_to_cart_button', function(e) {  // ajax add cart request var $thisbutton = $( );  if ( $thisbutton.is( '.product_type_simple' ) ) {      if ( ! $thisbutton.attr( 'data-product_id' ) )         return true;      $thisbutton.removeclass( 'added' );     $thisbutton.addclass( 'loading' );      var data = {         action: 'woocommerce_add_to_cart',     };      $.each( $thisbutton.data(), function( key, value ) {         data[key] = value;     });      // trigger event     $( 'body' ).trigger( 'adding_to_cart', [ $thisbutton, data ] );      // ajax action     $.post( wc_add_to_cart_params.ajax_url, data, function( response ) {          if ( ! response )             return;          var this_page = window.location.tostring();          this_page = this_page.replace( 'add-to-cart', 'added-to-cart' );          if ( response.error && response.product_url ) {             window.location = response.product_url;             return;         }          // redirect cart option         if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) {              window.location = wc_add_to_cart_params.cart_url;             return;          } else {              $thisbutton.removeclass( 'loading' );              fragments = response.fragments;             cart_hash = response.cart_hash;              // block fragments class             if ( fragments ) {                 $.each( fragments, function( key, value ) {                     $( key ).addclass( 'updating' );                 });             }              // block widgets , fragments             $( '.shop_table.cart, .updating, .cart_totals' ).fadeto( '400', '0.6' ).block({                 message: null,                 overlaycss: {                     opacity: 0.6                 }             });              // changes button classes             $thisbutton.addclass( 'added' );              // view cart text             if ( ! wc_add_to_cart_params.is_cart && $thisbutton.parent().find( '.added_to_cart' ).size() === 0 ) {                 $thisbutton.after( ' <a href="' + wc_add_to_cart_params.cart_url + '" class="added_to_cart wc-forward" title="' +                     wc_add_to_cart_params.i18n_view_cart + '">' + wc_add_to_cart_params.i18n_view_cart + '</a>' );             }              // replace fragments             if ( fragments ) {                 $.each( fragments, function( key, value ) {                     $( key ).replacewith( value );                 });             }              // unblock             $( '.widget_shopping_cart, .updating' ).stop( true ).css( 'opacity', '1' ).unblock();              // cart page elements             $( '.shop_table.cart' ).load( this_page + ' .shop_table.cart:eq(0) > *', function() {                  $( '.shop_table.cart' ).stop( true ).css( 'opacity', '1' ).unblock();                  $( 'body' ).trigger( 'cart_page_refreshed' );             });              $( '.cart_totals' ).load( this_page + ' .cart_totals:eq(0) > *', function() {                 $( '.cart_totals' ).stop( true ).css( 'opacity', '1' ).unblock();             });              // trigger event themes can refresh other areas             $( 'body' ).trigger( 'added_to_cart', [ fragments, cart_hash, $thisbutton ] );         }     });      return false;  }  return true; }); 

is there has done similar?

if here woocommerce repo, can see add-to-cart.js localized class.

unfortunately, there isn't filter add own link. try copying add-to-cart.js theme , set new src of registered add-to-cart.js new local copy, using this method.

from there can alter this conditional found in woocommerce repo.

so, technically yes, could this, there caveats:

  • you need repeat process variation products
  • if translation concern, need address well
  • any time plugin updates, have comb through these files differences break functionality or cause security issue.

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -