2017 © Pedro Peláez
 

library wc-toolkit

Better woocommerce endpoints

image

framecreative/wc-toolkit

Better woocommerce endpoints

  • Friday, March 23, 2018
  • by framecreative
  • Repository
  • 2 Watchers
  • 0 Stars
  • 518 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 23 % Grown

The README.md

WC Toolkit

Better ajax endpoints for woocommerce, (*1)

Creates the following ajax endpoints: - add_to_cart - remove_from_cart - cart_set_quantity - add_coupon - remove_coupon - cart_fragments, (*2)

Install

composer require framecreative/wc-toolkit, (*3)

Setup

Add new \WC_Toolkit\WC_Toolkit(); to your function.php or anywhere in your code you initialise your theme., (*4)

Then use the filters woocommerce_fragments_data or woocommerce_fragments_html to add your custom cart fragments, (*5)

Upgrading to version 2

Ajax success responses are now sent with wp_send_json_success instead of wp_send_json. So JS fragment code will need to refer to response.data.fragments instead of response.fragments., (*6)

Reset UI

Using new \WC_Toolkit\UI_Reset(); will dequeue all Woocommerce styles, pretty photo js/css, select2 js/css, and the default cart fragments js., (*7)

Example

Add data to fragments, (*8)

add_filter('woocommerce_fragments_data', function($fragments)
  {
    $fragments['span.js-cart-total'] = '<span class="js-cart-total">' . WC()->cart->get_cart_total() . '</span>';
    return $fragments;
  }
);

Create jQuery ajax call, (*9)

var endpoint = 'add_to_cart';
var addToCartUrl = wc_add_to_cart_params.wc_ajax_url.replace('%%endpoint%%', `site_${endpoint}`));
var data = { product_id: 1, quantity: 1};

$.ajax({
  url: addToCartUrl,
  data: data,
  method: 'POST'
})


The Versions

23/03 2018

dev-master

9999999-dev

Better woocommerce endpoints

  Sources   Download

MIT

The Requires

  • php >=5.2

 

by Frame Creative

23/03 2018

1.4.3

1.4.3.0

Better woocommerce endpoints

  Sources   Download

MIT

The Requires

  • php >=5.2

 

by Frame Creative

17/10 2017

1.4.2

1.4.2.0

Better woocommerce endpoints

  Sources   Download

MIT

The Requires

  • php >=5.2

 

by Frame Creative

31/08 2017

1.4.1

1.4.1.0

Better woocommerce endpoints

  Sources   Download

MIT

The Requires

  • php >=5.2

 

by Frame Creative

11/08 2017

1.4.0

1.4.0.0

Better woocommerce endpoints

  Sources   Download

MIT

The Requires

  • php >=5.2

 

by Frame Creative

10/08 2017

1.3.0

1.3.0.0

Better woocommerce endpoints

  Sources   Download

MIT

The Requires

  • php >=5.2

 

by Frame Creative

04/07 2017

1.2.0

1.2.0.0

Better woocommerce endpoints

  Sources   Download

MIT

The Requires

  • php >=5.2

 

by Frame Creative

04/07 2017

1.1.0

1.1.0.0

Better woocommerce endpoints

  Sources   Download

MIT

The Requires

  • php >=5.2

 

by Frame Creative

04/07 2017

1.0.0

1.0.0.0

Better woocommerce endpoints

  Sources   Download

MIT

The Requires

  • php >=5.2

 

by Frame Creative