WooCommerce Code Reference

WC_AJAX
in package

WC_Ajax class.

Table of Contents

add_ajax_events()  : mixed
Hook in methods - uses WordPress ajax handlers (admin-ajax).
add_attribute()  : mixed
Add an attribute row.
add_coupon_discount()  : mixed
Add order discount via ajax.
add_new_attribute()  : mixed
Add a new attribute via ajax function.
add_order_fee()  : mixed
Add order fee via ajax.
add_order_item()  : mixed
Add order item via ajax. Used on the edit order screen in WP Admin.
add_order_note()  : mixed
Add order note via ajax.
add_order_shipping()  : mixed
Add order shipping cost via ajax.
add_order_tax()  : mixed
Add order tax column via ajax.
add_to_cart()  : mixed
AJAX add to cart.
add_variation()  : mixed
Add variation via ajax function.
apply_coupon()  : mixed
AJAX apply coupon on checkout page.
bulk_edit_variations()  : mixed
Bulk edit variations via AJAX.
calc_line_taxes()  : mixed
Calc line tax.
checkout()  : mixed
Process ajax checkout form.
define_ajax()  : mixed
Set WC AJAX constant and headers.
delete_order_note()  : mixed
Delete order note via ajax.
delete_refund()  : mixed
Delete a refund.
do_wc_ajax()  : mixed
Check for WC Ajax request and fire action.
feature_product()  : mixed
Toggle Featured status of a product from admin.
get_cart_totals()  : mixed
AJAX receive updated cart_totals div.
get_customer_details()  : mixed
Get customer details via ajax.
get_customer_location()  : mixed
Locate user via AJAX.
get_endpoint()  : string
Get WC Ajax Endpoint.
get_order_details()  : mixed
Get order details.
get_refreshed_fragments()  : mixed
Get a refreshed cart fragment, including the mini cart HTML.
get_variation()  : mixed
Get a matching variation based on posted attributes.
grant_access_to_download()  : mixed
Grant download permissions via ajax function.
init()  : mixed
Hook in ajax handlers.
json_search_categories()  : mixed
Search for categories and return json.
json_search_customers()  : mixed
Search for customers and return json.
json_search_downloadable_products_and_variations()  : mixed
Search for downloadable product variations and return json.
json_search_products()  : mixed
Search for products and echo json.
json_search_products_and_variations()  : mixed
Search for product variations and return json.
link_all_variations()  : mixed
Link all variations via ajax function.
load_order_items()  : mixed
Load order items via ajax.
load_variations()  : mixed
Load variations via AJAX.
mark_order_status()  : mixed
Mark an order with a status.
product_ordering()  : mixed
Ajax request handling for product ordering.
rated()  : mixed
Triggered when clicking the rating footer.
refund_line_items()  : mixed
Handle a refund via the edit order screen.
remove_coupon()  : mixed
AJAX remove coupon on cart and checkout page.
remove_from_cart()  : mixed
AJAX remove from cart.
remove_order_coupon()  : mixed
Remove coupon from an order via ajax.
remove_order_item()  : mixed
Remove an order item.
remove_order_tax()  : mixed
Remove an order tax.
remove_variations()  : mixed
Delete variations via ajax function.
revoke_access_to_download()  : mixed
Delete download permissions via ajax function.
save_attributes()  : mixed
Save attributes via ajax.
save_order_items()  : mixed
Save order items via ajax.
save_variations()  : mixed
Save variations via AJAX.
shipping_classes_save_changes()  : mixed
Handle submissions from assets/js/wc-shipping-classes.js Backbone model.
shipping_zone_add_method()  : mixed
Handle submissions from assets/js/wc-shipping-zone-methods.js Backbone model.
shipping_zone_methods_save_changes()  : mixed
Handle submissions from assets/js/wc-shipping-zone-methods.js Backbone model.
shipping_zone_methods_save_settings()  : mixed
Save method settings
shipping_zones_save_changes()  : mixed
Handle submissions from assets/js/wc-shipping-zones.js Backbone model.
tax_rates_save_changes()  : mixed
Handle submissions from assets/js/settings-views-html-settings-tax.js Backbone model.
term_ordering()  : mixed
Ajax request handling for categories ordering.
toggle_gateway_enabled()  : mixed
Toggle payment gateway on or off via AJAX.
update_api_key()  : mixed
Create/Update API key.
update_order_review()  : mixed
AJAX update order review on checkout.
update_shipping_method()  : mixed
AJAX update shipping method on cart page.
maybe_add_order_item()  : array
Add order item via AJAX. This is refactored for better unit testing.
update_order_review_expired()  : mixed
Session has expired.
variation_bulk_action_delete_all()  : mixed
Bulk action - Delete all.
variation_bulk_action_toggle_downloadable()  : mixed
Bulk action - Toggle Downloadable Checkbox.
variation_bulk_action_toggle_enabled()  : mixed
Bulk action - Toggle Enabled.
variation_bulk_action_toggle_manage_stock()  : mixed
Bulk action - Toggle Manage Stock Checkbox.
variation_bulk_action_toggle_virtual()  : mixed
Bulk action - Toggle Virtual Checkbox.
variation_bulk_action_variable_download_expiry()  : mixed
Bulk action - Set Download Expiry.
variation_bulk_action_variable_download_limit()  : mixed
Bulk action - Set Download Limit.
variation_bulk_action_variable_height()  : mixed
Bulk action - Set Height.
variation_bulk_action_variable_length()  : mixed
Bulk action - Set Length.
variation_bulk_action_variable_regular_price()  : mixed
Bulk action - Set Regular Prices.
variation_bulk_action_variable_regular_price_decrease()  : mixed
Bulk action - Decrease Regular Prices.
variation_bulk_action_variable_regular_price_increase()  : mixed
Bulk action - Increase Regular Prices.
variation_bulk_action_variable_sale_price()  : mixed
Bulk action - Set Sale Prices.
variation_bulk_action_variable_sale_price_decrease()  : mixed
Bulk action - Decrease Sale Prices.
variation_bulk_action_variable_sale_price_increase()  : mixed
Bulk action - Increase Sale Prices.
variation_bulk_action_variable_sale_schedule()  : mixed
Bulk action - Sale Schedule.
variation_bulk_action_variable_stock()  : mixed
Bulk action - Set Stock.
variation_bulk_action_variable_stock_status_instock()  : mixed
Bulk action - Set Stock Status as In Stock.
variation_bulk_action_variable_stock_status_onbackorder()  : mixed
Bulk action - Set Stock Status as On Backorder.
variation_bulk_action_variable_stock_status_outofstock()  : mixed
Bulk action - Set Stock Status as Out of Stock.
variation_bulk_action_variable_weight()  : mixed
Bulk action - Set Weight.
variation_bulk_action_variable_width()  : mixed
Bulk action - Set Width.
variation_bulk_adjust_price()  : mixed
Bulk action - Set Price.
variation_bulk_set()  : mixed
Bulk set convenience function.
variation_bulk_toggle()  : mixed
Bulk toggle convenience function.
wc_ajax_headers()  : mixed
Send headers for WC Ajax Requests.

Methods

add_ajax_events()

Hook in methods - uses WordPress ajax handlers (admin-ajax).

public static add_ajax_events() : mixed
Return values
mixed

add_attribute()

Add an attribute row.

public static add_attribute() : mixed
Return values
mixed

add_coupon_discount()

Add order discount via ajax.

public static add_coupon_discount() : mixed
Tags
throws
Exception

If order or coupon is invalid.

Return values
mixed

add_new_attribute()

Add a new attribute via ajax function.

public static add_new_attribute() : mixed
Return values
mixed

add_order_fee()

Add order fee via ajax.

public static add_order_fee() : mixed
Tags
throws
Exception

If order is invalid.

Return values
mixed

add_order_item()

Add order item via ajax. Used on the edit order screen in WP Admin.

public static add_order_item() : mixed
Tags
throws
Exception

If order is invalid.

Return values
mixed

add_order_note()

Add order note via ajax.

public static add_order_note() : mixed
Return values
mixed

add_order_shipping()

Add order shipping cost via ajax.

public static add_order_shipping() : mixed
Tags
throws
Exception

If order is invalid.

Return values
mixed

add_order_tax()

Add order tax column via ajax.

public static add_order_tax() : mixed
Tags
throws
Exception

If order or tax rate is invalid.

Return values
mixed

add_variation()

Add variation via ajax function.

public static add_variation() : mixed
Return values
mixed

apply_coupon()

AJAX apply coupon on checkout page.

public static apply_coupon() : mixed
Return values
mixed

bulk_edit_variations()

Bulk edit variations via AJAX.

public static bulk_edit_variations() : mixed
Tags
uses
WC_AJAX::variation_bulk_set()
uses
WC_AJAX::variation_bulk_adjust_price()
uses
WC_AJAX::variation_bulk_action_variable_sale_price_decrease()
uses
WC_AJAX::variation_bulk_action_variable_sale_price_increase()
uses
WC_AJAX::variation_bulk_action_variable_regular_price_decrease()
uses
WC_AJAX::variation_bulk_action_variable_regular_price_increase()
uses
WC_AJAX::variation_bulk_action_variable_sale_schedule()
uses
WC_AJAX::variation_bulk_action_delete_all()
uses
WC_AJAX::variation_bulk_action_variable_download_expiry()
uses
WC_AJAX::variation_bulk_action_variable_download_limit()
uses
WC_AJAX::variation_bulk_action_variable_height()
uses
WC_AJAX::variation_bulk_action_variable_width()
uses
WC_AJAX::variation_bulk_action_variable_length()
uses
WC_AJAX::variation_bulk_action_variable_weight()
uses
WC_AJAX::variation_bulk_action_variable_stock()
uses
WC_AJAX::variation_bulk_action_variable_sale_price()
uses
WC_AJAX::variation_bulk_action_variable_regular_price()
uses
WC_AJAX::variation_bulk_action_toggle_manage_stock()
uses
WC_AJAX::variation_bulk_action_toggle_virtual()
uses
WC_AJAX::variation_bulk_action_toggle_downloadable()
uses
WC_AJAX::variation_bulk_action_toggle_enabled
Return values
mixed

define_ajax()

Set WC AJAX constant and headers.

public static define_ajax() : mixed
Return values
mixed

delete_order_note()

Delete order note via ajax.

public static delete_order_note() : mixed
Return values
mixed

do_wc_ajax()

Check for WC Ajax request and fire action.

public static do_wc_ajax() : mixed
Return values
mixed

feature_product()

Toggle Featured status of a product from admin.

public static feature_product() : mixed
Return values
mixed

get_cart_totals()

AJAX receive updated cart_totals div.

public static get_cart_totals() : mixed
Return values
mixed

get_customer_details()

Get customer details via ajax.

public static get_customer_details() : mixed
Return values
mixed

get_customer_location()

Locate user via AJAX.

public static get_customer_location() : mixed
Return values
mixed

get_endpoint()

Get WC Ajax Endpoint.

public static get_endpoint([string $request = '' ]) : string
Parameters
$request : string = ''

Optional.

Return values
string

get_order_details()

Get order details.

public static get_order_details() : mixed
Return values
mixed

get_refreshed_fragments()

Get a refreshed cart fragment, including the mini cart HTML.

public static get_refreshed_fragments() : mixed
Return values
mixed

get_variation()

Get a matching variation based on posted attributes.

public static get_variation() : mixed
Return values
mixed

grant_access_to_download()

Grant download permissions via ajax function.

public static grant_access_to_download() : mixed
Return values
mixed

json_search_categories()

Search for categories and return json.

public static json_search_categories() : mixed
Return values
mixed

json_search_customers()

Search for customers and return json.

public static json_search_customers() : mixed
Return values
mixed

json_search_products()

Search for products and echo json.

public static json_search_products([string $term = '' ][, bool $include_variations = false ]) : mixed
Parameters
$term : string = ''

(default: '') Term to search for.

$include_variations : bool = false

in search or not.

Return values
mixed

Link all variations via ajax function.

public static link_all_variations() : mixed
Return values
mixed

load_order_items()

Load order items via ajax.

public static load_order_items() : mixed
Return values
mixed

load_variations()

Load variations via AJAX.

public static load_variations() : mixed
Return values
mixed

mark_order_status()

Mark an order with a status.

public static mark_order_status() : mixed
Return values
mixed

rated()

Triggered when clicking the rating footer.

public static rated() : mixed
Return values
mixed

refund_line_items()

Handle a refund via the edit order screen.

public static refund_line_items() : mixed
Tags
throws
Exception

To return errors.

Return values
mixed

remove_coupon()

AJAX remove coupon on cart and checkout page.

public static remove_coupon() : mixed
Return values
mixed

remove_from_cart()

AJAX remove from cart.

public static remove_from_cart() : mixed
Return values
mixed

remove_order_coupon()

Remove coupon from an order via ajax.

public static remove_order_coupon() : mixed
Tags
throws
Exception

If order or coupon is invalid.

Return values
mixed

remove_order_item()

Remove an order item.

public static remove_order_item() : mixed
Tags
throws
Exception

If order is invalid.

Return values
mixed

remove_order_tax()

Remove an order tax.

public static remove_order_tax() : mixed
Tags
throws
Exception

If there is an error whilst deleting the rate.

Return values
mixed

remove_variations()

Delete variations via ajax function.

public static remove_variations() : mixed
Return values
mixed

revoke_access_to_download()

Delete download permissions via ajax function.

public static revoke_access_to_download() : mixed
Return values
mixed

save_attributes()

Save attributes via ajax.

public static save_attributes() : mixed
Return values
mixed

save_order_items()

Save order items via ajax.

public static save_order_items() : mixed
Return values
mixed

save_variations()

Save variations via AJAX.

public static save_variations() : mixed
Return values
mixed

shipping_classes_save_changes()

Handle submissions from assets/js/wc-shipping-classes.js Backbone model.

public static shipping_classes_save_changes() : mixed
Return values
mixed

shipping_zone_add_method()

Handle submissions from assets/js/wc-shipping-zone-methods.js Backbone model.

public static shipping_zone_add_method() : mixed
Return values
mixed

shipping_zone_methods_save_changes()

Handle submissions from assets/js/wc-shipping-zone-methods.js Backbone model.

public static shipping_zone_methods_save_changes() : mixed
Return values
mixed

shipping_zone_methods_save_settings()

Save method settings

public static shipping_zone_methods_save_settings() : mixed
Return values
mixed

shipping_zones_save_changes()

Handle submissions from assets/js/wc-shipping-zones.js Backbone model.

public static shipping_zones_save_changes() : mixed
Return values
mixed

tax_rates_save_changes()

Handle submissions from assets/js/settings-views-html-settings-tax.js Backbone model.

public static tax_rates_save_changes() : mixed
Return values
mixed

term_ordering()

Ajax request handling for categories ordering.

public static term_ordering() : mixed
Return values
mixed

toggle_gateway_enabled()

Toggle payment gateway on or off via AJAX.

public static toggle_gateway_enabled() : mixed
Tags
since
3.4.0
Return values
mixed

update_api_key()

Create/Update API key.

public static update_api_key() : mixed
Tags
throws
Exception

On invalid or empty description, user, or permissions.

Return values
mixed

update_order_review()

AJAX update order review on checkout.

public static update_order_review() : mixed
Return values
mixed

update_shipping_method()

AJAX update shipping method on cart page.

public static update_shipping_method() : mixed
Return values
mixed

maybe_add_order_item()

Add order item via AJAX. This is refactored for better unit testing.

private static maybe_add_order_item(int $order_id, string|array $items, array $items_to_add) : array
Parameters
$order_id : int

ID of order to add items to.

$items : string|array

Existing items in order. Empty string if no items to add.

$items_to_add : array

Array of items to add.

Tags
throws
Exception

When unable to add item.

Return values
arrayFragments to render and notes HTML.

update_order_review_expired()

Session has expired.

private static update_order_review_expired() : mixed
Return values
mixed

variation_bulk_action_delete_all()

Bulk action - Delete all.

private static variation_bulk_action_delete_all(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_toggle_downloadable()

Bulk action - Toggle Downloadable Checkbox.

private static variation_bulk_action_toggle_downloadable(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_toggle_enabled()

Bulk action - Toggle Enabled.

private static variation_bulk_action_toggle_enabled(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_toggle_manage_stock()

Bulk action - Toggle Manage Stock Checkbox.

private static variation_bulk_action_toggle_manage_stock(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_toggle_virtual()

Bulk action - Toggle Virtual Checkbox.

private static variation_bulk_action_toggle_virtual(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_download_expiry()

Bulk action - Set Download Expiry.

private static variation_bulk_action_variable_download_expiry(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_download_limit()

Bulk action - Set Download Limit.

private static variation_bulk_action_variable_download_limit(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_height()

Bulk action - Set Height.

private static variation_bulk_action_variable_height(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_length()

Bulk action - Set Length.

private static variation_bulk_action_variable_length(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_regular_price()

Bulk action - Set Regular Prices.

private static variation_bulk_action_variable_regular_price(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_regular_price_decrease()

Bulk action - Decrease Regular Prices.

private static variation_bulk_action_variable_regular_price_decrease(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_regular_price_increase()

Bulk action - Increase Regular Prices.

private static variation_bulk_action_variable_regular_price_increase(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_sale_price()

Bulk action - Set Sale Prices.

private static variation_bulk_action_variable_sale_price(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_sale_price_decrease()

Bulk action - Decrease Sale Prices.

private static variation_bulk_action_variable_sale_price_decrease(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_sale_price_increase()

Bulk action - Increase Sale Prices.

private static variation_bulk_action_variable_sale_price_increase(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_sale_schedule()

Bulk action - Sale Schedule.

private static variation_bulk_action_variable_sale_schedule(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_stock()

Bulk action - Set Stock.

private static variation_bulk_action_variable_stock(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_stock_status_instock()

Bulk action - Set Stock Status as In Stock.

private static variation_bulk_action_variable_stock_status_instock(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_stock_status_onbackorder()

Bulk action - Set Stock Status as On Backorder.

private static variation_bulk_action_variable_stock_status_onbackorder(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_stock_status_outofstock()

Bulk action - Set Stock Status as Out of Stock.

private static variation_bulk_action_variable_stock_status_outofstock(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_weight()

Bulk action - Set Weight.

private static variation_bulk_action_variable_weight(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_action_variable_width()

Bulk action - Set Width.

private static variation_bulk_action_variable_width(array $variations, array $data) : mixed
Parameters
$variations : array

List of variations.

$data : array

Data to set.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_adjust_price()

Bulk action - Set Price.

private static variation_bulk_adjust_price(array $variations, string $field, string $operator, string $value) : mixed
Parameters
$variations : array

List of variations.

$field : string

price being adjusted _regular_price or _sale_price.

$operator : string
  • or -.
$value : string

Price or Percent.

Tags
used-by

bulk_edit_variations

Return values
mixed

variation_bulk_set()

Bulk set convenience function.

private static variation_bulk_set(array $variations, string $field, string $value) : mixed
Parameters
$variations : array

List of variations.

$field : string

Field to set.

$value : string

to set.

Return values
mixed

variation_bulk_toggle()

Bulk toggle convenience function.

private static variation_bulk_toggle(array $variations, string $field) : mixed
Parameters
$variations : array

List of variations.

$field : string

Field to toggle.

Return values
mixed

wc_ajax_headers()

Send headers for WC Ajax Requests.

private static wc_ajax_headers() : mixed
Tags
since
2.5.0
Return values
mixed