2013-11-14 12:13:34 +00:00
< ? php
/**
2018-02-22 14:30:13 +00:00
* WooCommerce WC_AJAX . AJAX Event Handlers .
2013-11-14 12:13:34 +00:00
*
2018-12-14 18:13:08 +00:00
* @ class WC_AJAX
2020-08-05 16:36:24 +00:00
* @ package WooCommerce\Classes
2018-02-22 14:30:13 +00:00
*/
2020-01-29 05:21:29 +00:00
use Automattic\Jetpack\Constants ;
2020-10-01 08:57:12 +00:00
use Automattic\WooCommerce\Utilities\NumberUtil ;
2020-01-29 05:21:29 +00:00
2018-02-22 14:30:13 +00:00
defined ( 'ABSPATH' ) || exit ;
/**
* WC_Ajax class .
2013-11-14 12:13:34 +00:00
*/
class WC_AJAX {
/**
2015-11-03 13:31:20 +00:00
* Hook in ajax handlers .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function init () {
2015-11-30 12:10:31 +00:00
add_action ( 'init' , array ( __CLASS__ , 'define_ajax' ), 0 );
add_action ( 'template_redirect' , array ( __CLASS__ , 'do_wc_ajax' ), 0 );
2015-03-20 12:28:26 +00:00
self :: add_ajax_events ();
}
/**
2015-11-03 13:31:20 +00:00
* Get WC Ajax Endpoint .
2016-11-24 11:50:58 +00:00
*
2018-12-14 18:13:08 +00:00
* @ param string $request Optional .
*
2015-03-20 12:28:26 +00:00
* @ return string
*/
2015-06-19 12:30:57 +00:00
public static function get_endpoint ( $request = '' ) {
2018-06-22 12:32:21 +00:00
return esc_url_raw ( apply_filters ( 'woocommerce_ajax_get_endpoint' , add_query_arg ( 'wc-ajax' , $request , remove_query_arg ( array ( 'remove_item' , 'add-to-cart' , 'added-to-cart' , 'order_again' , '_wpnonce' ), home_url ( '/' , 'relative' ) ) ), $request ) );
2015-03-20 12:28:26 +00:00
}
2015-07-31 18:15:17 +00:00
/**
2015-08-23 20:17:03 +00:00
* Set WC AJAX constant and headers .
2015-07-31 18:15:17 +00:00
*/
public static function define_ajax () {
2019-02-15 17:09:45 +00:00
// phpcs:disable
2015-07-31 18:15:17 +00:00
if ( ! empty ( $_GET [ 'wc-ajax' ] ) ) {
2016-11-24 14:20:58 +00:00
wc_maybe_define_constant ( 'DOING_AJAX' , true );
wc_maybe_define_constant ( 'WC_DOING_AJAX' , true );
2015-08-13 09:27:02 +00:00
if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
2019-03-13 12:10:53 +00:00
@ ini_set ( 'display_errors' , 0 ); // Turn off display_errors during AJAX events to prevent malformed JSON.
2015-08-13 09:27:02 +00:00
}
2015-11-04 13:35:32 +00:00
$GLOBALS [ 'wpdb' ] -> hide_errors ();
2015-07-31 18:15:17 +00:00
}
2019-02-15 17:09:45 +00:00
// phpcs:enable
2015-07-31 18:15:17 +00:00
}
2015-11-30 12:10:31 +00:00
/**
2016-11-24 11:50:58 +00:00
* Send headers for WC Ajax Requests .
*
2015-11-30 12:10:31 +00:00
* @ since 2.5 . 0
*/
private static function wc_ajax_headers () {
2019-02-15 17:23:34 +00:00
if ( ! headers_sent () ) {
send_origin_headers ();
send_nosniff_header ();
wc_nocache_headers ();
header ( 'Content-Type: text/html; charset=' . get_option ( 'blog_charset' ) );
header ( 'X-Robots-Tag: noindex' );
status_header ( 200 );
2020-01-29 05:21:29 +00:00
} elseif ( Constants :: is_true ( 'WP_DEBUG' ) ) {
2019-02-15 17:23:34 +00:00
headers_sent ( $file , $line );
trigger_error ( " wc_ajax_headers cannot set headers - headers already sent by { $file } on line { $line } " , E_USER_NOTICE ); // @codingStandardsIgnoreLine
}
2015-11-30 12:10:31 +00:00
}
2015-03-20 12:28:26 +00:00
/**
2015-11-03 13:31:20 +00:00
* Check for WC Ajax request and fire action .
2015-03-20 12:28:26 +00:00
*/
public static function do_wc_ajax () {
global $wp_query ;
2019-11-21 17:19:56 +00:00
// phpcs:disable WordPress.Security.NonceVerification.Recommended
2015-03-20 13:10:47 +00:00
if ( ! empty ( $_GET [ 'wc-ajax' ] ) ) {
2018-02-22 15:37:01 +00:00
$wp_query -> set ( 'wc-ajax' , sanitize_text_field ( wp_unslash ( $_GET [ 'wc-ajax' ] ) ) );
2015-03-20 13:10:47 +00:00
}
2018-02-22 15:37:01 +00:00
$action = $wp_query -> get ( 'wc-ajax' );
if ( $action ) {
2015-11-30 12:10:31 +00:00
self :: wc_ajax_headers ();
2018-05-02 13:28:53 +00:00
$action = sanitize_text_field ( $action );
do_action ( 'wc_ajax_' . $action );
2017-01-29 20:43:25 +00:00
wp_die ();
2015-07-07 01:50:35 +00:00
}
2019-02-15 17:09:45 +00:00
// phpcs:enable
2015-03-20 12:28:26 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Hook in methods - uses WordPress ajax handlers ( admin - ajax ) .
2015-03-20 12:28:26 +00:00
*/
public static function add_ajax_events () {
2019-02-15 17:09:45 +00:00
$ajax_events_nopriv = array (
'get_refreshed_fragments' ,
'apply_coupon' ,
'remove_coupon' ,
'update_shipping_method' ,
'get_cart_totals' ,
'update_order_review' ,
'add_to_cart' ,
'remove_from_cart' ,
'checkout' ,
'get_variation' ,
'get_customer_location' ,
2013-11-14 12:13:34 +00:00
);
2014-01-26 09:19:17 +00:00
2019-02-15 17:09:45 +00:00
foreach ( $ajax_events_nopriv as $ajax_event ) {
2014-05-28 13:52:50 +00:00
add_action ( 'wp_ajax_woocommerce_' . $ajax_event , array ( __CLASS__ , $ajax_event ) );
2019-02-15 17:09:45 +00:00
add_action ( 'wp_ajax_nopriv_woocommerce_' . $ajax_event , array ( __CLASS__ , $ajax_event ) );
2013-11-14 12:13:34 +00:00
2019-02-15 17:09:45 +00:00
// WC AJAX can be used for frontend ajax requests.
add_action ( 'wc_ajax_' . $ajax_event , array ( __CLASS__ , $ajax_event ) );
}
2015-03-20 12:28:26 +00:00
2019-02-15 17:09:45 +00:00
$ajax_events = array (
'feature_product' ,
'mark_order_status' ,
'get_order_details' ,
'add_attribute' ,
'add_new_attribute' ,
'remove_variations' ,
'save_attributes' ,
'add_variation' ,
'link_all_variations' ,
'revoke_access_to_download' ,
'grant_access_to_download' ,
'get_customer_details' ,
'add_order_item' ,
'add_order_fee' ,
'add_order_shipping' ,
'add_order_tax' ,
'add_coupon_discount' ,
'remove_order_coupon' ,
'remove_order_item' ,
'remove_order_tax' ,
'reduce_order_item_stock' ,
'increase_order_item_stock' ,
'add_order_item_meta' ,
'remove_order_item_meta' ,
'calc_line_taxes' ,
'save_order_items' ,
'load_order_items' ,
'add_order_note' ,
'delete_order_note' ,
'json_search_products' ,
'json_search_products_and_variations' ,
'json_search_downloadable_products_and_variations' ,
'json_search_customers' ,
'json_search_categories' ,
2021-02-19 23:28:07 +00:00
'json_search_pages' ,
2019-02-15 17:09:45 +00:00
'term_ordering' ,
'product_ordering' ,
'refund_line_items' ,
'delete_refund' ,
'rated' ,
'update_api_key' ,
'load_variations' ,
'save_variations' ,
'bulk_edit_variations' ,
'tax_rates_save_changes' ,
'shipping_zones_save_changes' ,
'shipping_zone_add_method' ,
'shipping_zone_methods_save_changes' ,
'shipping_zone_methods_save_settings' ,
'shipping_classes_save_changes' ,
'toggle_gateway_enabled' ,
);
foreach ( $ajax_events as $ajax_event ) {
add_action ( 'wp_ajax_woocommerce_' . $ajax_event , array ( __CLASS__ , $ajax_event ) );
2013-11-14 12:13:34 +00:00
}
}
/**
2016-11-24 11:50:58 +00:00
* Get a refreshed cart fragment , including the mini cart HTML .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function get_refreshed_fragments () {
2013-11-14 12:13:34 +00:00
ob_start ();
2013-11-25 14:16:26 +00:00
woocommerce_mini_cart ();
2013-11-14 12:13:34 +00:00
$mini_cart = ob_get_clean ();
$data = array (
2018-02-22 15:37:01 +00:00
'fragments' => apply_filters (
2019-02-15 17:09:45 +00:00
'woocommerce_add_to_cart_fragments' ,
array (
2016-08-27 01:46:45 +00:00
'div.widget_shopping_cart_content' => '<div class="widget_shopping_cart_content">' . $mini_cart . '</div>' ,
2013-11-14 12:13:34 +00:00
)
),
2018-08-14 16:08:55 +00:00
'cart_hash' => WC () -> cart -> get_cart_hash (),
2013-11-14 12:13:34 +00:00
);
2014-05-31 07:32:22 +00:00
wp_send_json ( $data );
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* AJAX apply coupon on checkout page .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function apply_coupon () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'apply-coupon' , 'security' );
if ( ! empty ( $_POST [ 'coupon_code' ] ) ) {
2019-03-06 11:44:54 +00:00
WC () -> cart -> add_discount ( wc_format_coupon_code ( wp_unslash ( $_POST [ 'coupon_code' ] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2013-11-14 12:13:34 +00:00
} else {
2013-11-18 11:44:22 +00:00
wc_add_notice ( WC_Coupon :: get_generic_coupon_error ( WC_Coupon :: E_WC_COUPON_PLEASE_ENTER ), 'error' );
2013-11-14 12:13:34 +00:00
}
2013-11-18 11:44:22 +00:00
wc_print_notices ();
2017-01-29 20:43:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
2014-12-08 06:15:03 +00:00
/**
2015-11-03 13:31:20 +00:00
* AJAX remove coupon on cart and checkout page .
2014-12-08 06:15:03 +00:00
*/
public static function remove_coupon () {
check_ajax_referer ( 'remove-coupon' , 'security' );
2019-03-06 11:44:54 +00:00
$coupon = isset ( $_POST [ 'coupon' ] ) ? wc_format_coupon_code ( wp_unslash ( $_POST [ 'coupon' ] ) ) : false ; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2014-12-08 06:15:03 +00:00
2017-03-22 10:53:18 +00:00
if ( empty ( $coupon ) ) {
2016-04-12 15:07:11 +00:00
wc_add_notice ( __ ( 'Sorry there was a problem removing this coupon.' , 'woocommerce' ), 'error' );
2014-12-08 06:15:03 +00:00
} else {
WC () -> cart -> remove_coupon ( $coupon );
wc_add_notice ( __ ( 'Coupon has been removed.' , 'woocommerce' ) );
}
wc_print_notices ();
2017-01-29 20:43:25 +00:00
wp_die ();
2014-12-08 06:15:03 +00:00
}
2013-11-14 12:13:34 +00:00
/**
2015-11-03 13:31:20 +00:00
* AJAX update shipping method on cart page .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function update_shipping_method () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'update-shipping-method' , 'security' );
2016-11-24 14:20:58 +00:00
wc_maybe_define_constant ( 'WOOCOMMERCE_CART' , true );
2013-11-14 12:13:34 +00:00
$chosen_shipping_methods = WC () -> session -> get ( 'chosen_shipping_methods' );
2019-02-15 17:09:45 +00:00
$posted_shipping_methods = isset ( $_POST [ 'shipping_method' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'shipping_method' ] ) ) : array ();
2013-11-14 12:13:34 +00:00
2019-02-15 17:09:45 +00:00
if ( is_array ( $posted_shipping_methods ) ) {
foreach ( $posted_shipping_methods as $i => $value ) {
$chosen_shipping_methods [ $i ] = $value ;
2014-04-25 11:30:39 +00:00
}
}
2013-11-14 12:13:34 +00:00
WC () -> session -> set ( 'chosen_shipping_methods' , $chosen_shipping_methods );
2016-11-24 14:20:58 +00:00
self :: get_cart_totals ();
2013-11-14 12:13:34 +00:00
}
2016-02-11 06:26:41 +00:00
/**
* AJAX receive updated cart_totals div .
*/
public static function get_cart_totals () {
2016-11-24 14:20:58 +00:00
wc_maybe_define_constant ( 'WOOCOMMERCE_CART' , true );
2016-02-11 06:26:41 +00:00
WC () -> cart -> calculate_totals ();
woocommerce_cart_totals ();
2017-01-29 20:43:25 +00:00
wp_die ();
2016-02-11 06:26:41 +00:00
}
2013-11-14 12:13:34 +00:00
/**
2016-11-24 14:20:58 +00:00
* Session has expired .
2013-11-14 12:13:34 +00:00
*/
2016-11-24 14:20:58 +00:00
private static function update_order_review_expired () {
2018-02-22 15:37:01 +00:00
wp_send_json (
array (
'fragments' => apply_filters (
2019-02-15 17:09:45 +00:00
'woocommerce_update_order_review_fragments' ,
array (
2018-02-22 15:37:01 +00:00
'form.woocommerce-checkout' => '<div class="woocommerce-error">' . __ ( 'Sorry, your session has expired.' , 'woocommerce' ) . ' <a href="' . esc_url ( wc_get_page_permalink ( 'shop' ) ) . '" class="wc-backward">' . __ ( 'Return to shop' , 'woocommerce' ) . '</a></div>' ,
)
),
)
);
2016-11-24 14:20:58 +00:00
}
2013-11-14 12:13:34 +00:00
2016-11-24 14:20:58 +00:00
/**
2016-11-24 17:50:24 +00:00
* AJAX update order review on checkout .
2016-11-24 14:20:58 +00:00
*/
public static function update_order_review () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'update-order-review' , 'security' );
2016-11-24 14:20:58 +00:00
wc_maybe_define_constant ( 'WOOCOMMERCE_CHECKOUT' , true );
2013-11-14 12:13:34 +00:00
2018-06-11 20:29:16 +00:00
if ( WC () -> cart -> is_empty () && ! is_customize_preview () && apply_filters ( 'woocommerce_checkout_update_order_review_expired' , true ) ) {
2016-11-24 14:20:58 +00:00
self :: update_order_review_expired ();
2013-11-14 12:13:34 +00:00
}
2019-02-15 17:09:45 +00:00
do_action ( 'woocommerce_checkout_update_order_review' , isset ( $_POST [ 'post_data' ] ) ? wp_unslash ( $_POST [ 'post_data' ] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2013-11-14 12:13:34 +00:00
$chosen_shipping_methods = WC () -> session -> get ( 'chosen_shipping_methods' );
2019-02-15 17:09:45 +00:00
$posted_shipping_methods = isset ( $_POST [ 'shipping_method' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'shipping_method' ] ) ) : array ();
2013-11-14 12:13:34 +00:00
2019-02-15 17:09:45 +00:00
if ( is_array ( $posted_shipping_methods ) ) {
foreach ( $posted_shipping_methods as $i => $value ) {
$chosen_shipping_methods [ $i ] = $value ;
2014-05-12 13:04:36 +00:00
}
}
2013-11-14 12:13:34 +00:00
WC () -> session -> set ( 'chosen_shipping_methods' , $chosen_shipping_methods );
2019-02-15 17:09:45 +00:00
WC () -> session -> set ( 'chosen_payment_method' , empty ( $_POST [ 'payment_method' ] ) ? '' : wc_clean ( wp_unslash ( $_POST [ 'payment_method' ] ) ) );
2018-02-22 15:37:01 +00:00
WC () -> customer -> set_props (
array (
2019-02-15 17:09:45 +00:00
'billing_country' => isset ( $_POST [ 'country' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'country' ] ) ) : null ,
'billing_state' => isset ( $_POST [ 'state' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'state' ] ) ) : null ,
'billing_postcode' => isset ( $_POST [ 'postcode' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'postcode' ] ) ) : null ,
'billing_city' => isset ( $_POST [ 'city' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'city' ] ) ) : null ,
'billing_address_1' => isset ( $_POST [ 'address' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'address' ] ) ) : null ,
'billing_address_2' => isset ( $_POST [ 'address_2' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'address_2' ] ) ) : null ,
2018-02-22 15:37:01 +00:00
)
);
2013-11-14 12:13:34 +00:00
2014-04-08 15:28:27 +00:00
if ( wc_ship_to_billing_address_only () ) {
2018-02-22 15:37:01 +00:00
WC () -> customer -> set_props (
array (
2019-02-15 17:09:45 +00:00
'shipping_country' => isset ( $_POST [ 'country' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'country' ] ) ) : null ,
'shipping_state' => isset ( $_POST [ 'state' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'state' ] ) ) : null ,
'shipping_postcode' => isset ( $_POST [ 'postcode' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'postcode' ] ) ) : null ,
'shipping_city' => isset ( $_POST [ 'city' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'city' ] ) ) : null ,
'shipping_address_1' => isset ( $_POST [ 'address' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'address' ] ) ) : null ,
'shipping_address_2' => isset ( $_POST [ 'address_2' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'address_2' ] ) ) : null ,
2018-02-22 15:37:01 +00:00
)
);
2014-02-14 11:19:32 +00:00
} else {
2018-02-22 15:37:01 +00:00
WC () -> customer -> set_props (
array (
2019-02-15 17:09:45 +00:00
'shipping_country' => isset ( $_POST [ 's_country' ] ) ? wc_clean ( wp_unslash ( $_POST [ 's_country' ] ) ) : null ,
'shipping_state' => isset ( $_POST [ 's_state' ] ) ? wc_clean ( wp_unslash ( $_POST [ 's_state' ] ) ) : null ,
'shipping_postcode' => isset ( $_POST [ 's_postcode' ] ) ? wc_clean ( wp_unslash ( $_POST [ 's_postcode' ] ) ) : null ,
'shipping_city' => isset ( $_POST [ 's_city' ] ) ? wc_clean ( wp_unslash ( $_POST [ 's_city' ] ) ) : null ,
'shipping_address_1' => isset ( $_POST [ 's_address' ] ) ? wc_clean ( wp_unslash ( $_POST [ 's_address' ] ) ) : null ,
'shipping_address_2' => isset ( $_POST [ 's_address_2' ] ) ? wc_clean ( wp_unslash ( $_POST [ 's_address_2' ] ) ) : null ,
2018-02-22 15:37:01 +00:00
)
);
2017-09-08 13:54:15 +00:00
}
2019-02-15 17:09:45 +00:00
if ( isset ( $_POST [ 'has_full_address' ] ) && wc_string_to_bool ( wc_clean ( wp_unslash ( $_POST [ 'has_full_address' ] ) ) ) ) {
2017-09-08 13:54:15 +00:00
WC () -> customer -> set_calculated_shipping ( true );
} else {
WC () -> customer -> set_calculated_shipping ( false );
2014-02-14 11:19:32 +00:00
}
2013-11-14 12:13:34 +00:00
2016-03-09 20:49:02 +00:00
WC () -> customer -> save ();
2019-02-22 16:43:42 +00:00
2019-03-05 13:31:14 +00:00
// Calculate shipping before totals. This will ensure any shipping methods that affect things like taxes are chosen prior to final totals being calculated. Ref: #22708.
2019-02-22 16:43:42 +00:00
WC () -> cart -> calculate_shipping ();
2013-11-14 12:13:34 +00:00
WC () -> cart -> calculate_totals ();
2019-01-29 11:05:02 +00:00
// Get order review fragment.
2014-11-26 14:19:53 +00:00
ob_start ();
woocommerce_order_review ();
$woocommerce_order_review = ob_get_clean ();
2019-01-29 11:05:02 +00:00
// Get checkout payment fragment.
2014-11-26 14:19:53 +00:00
ob_start ();
woocommerce_checkout_payment ();
$woocommerce_checkout_payment = ob_get_clean ();
2019-01-29 11:05:02 +00:00
// Get messages if reload checkout is not true.
2020-12-02 14:01:07 +00:00
$reload_checkout = isset ( WC () -> session -> reload_checkout );
2019-01-29 11:05:02 +00:00
if ( ! $reload_checkout ) {
2018-04-19 17:27:29 +00:00
$messages = wc_print_notices ( true );
} else {
$messages = '' ;
2014-12-04 08:40:49 +00:00
}
2016-11-24 14:20:58 +00:00
unset ( WC () -> session -> refresh_totals , WC () -> session -> reload_checkout );
2018-02-22 15:37:01 +00:00
wp_send_json (
array (
'result' => empty ( $messages ) ? 'success' : 'failure' ,
'messages' => $messages ,
2019-06-08 14:42:44 +00:00
'reload' => $reload_checkout ,
2018-02-22 15:37:01 +00:00
'fragments' => apply_filters (
2019-01-29 11:05:02 +00:00
'woocommerce_update_order_review_fragments' ,
array (
2018-02-22 15:37:01 +00:00
'.woocommerce-checkout-review-order-table' => $woocommerce_order_review ,
'.woocommerce-checkout-payment' => $woocommerce_checkout_payment ,
)
),
)
);
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* AJAX add to cart .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function add_to_cart () {
2014-09-16 12:24:02 +00:00
ob_start ();
2019-11-20 16:16:19 +00:00
// phpcs:disable WordPress.Security.NonceVerification.Missing
2019-02-15 17:09:45 +00:00
if ( ! isset ( $_POST [ 'product_id' ] ) ) {
return ;
}
2013-11-14 12:13:34 +00:00
$product_id = apply_filters ( 'woocommerce_add_to_cart_product_id' , absint ( $_POST [ 'product_id' ] ) );
2018-01-03 21:38:06 +00:00
$product = wc_get_product ( $product_id );
2019-02-15 17:09:45 +00:00
$quantity = empty ( $_POST [ 'quantity' ] ) ? 1 : wc_stock_amount ( wp_unslash ( $_POST [ 'quantity' ] ) );
2013-11-14 12:13:34 +00:00
$passed_validation = apply_filters ( 'woocommerce_add_to_cart_validation' , true , $product_id , $quantity );
2015-01-29 18:30:07 +00:00
$product_status = get_post_status ( $product_id );
2018-01-03 21:38:06 +00:00
$variation_id = 0 ;
$variation = array ();
2013-11-14 12:13:34 +00:00
2018-01-03 21:40:51 +00:00
if ( $product && 'variation' === $product -> get_type () ) {
2018-01-03 21:38:06 +00:00
$variation_id = $product_id ;
$product_id = $product -> get_parent_id ();
$variation = $product -> get_variation_attributes ();
}
if ( $passed_validation && false !== WC () -> cart -> add_to_cart ( $product_id , $quantity , $variation_id , $variation ) && 'publish' === $product_status ) {
2013-11-14 12:13:34 +00:00
do_action ( 'woocommerce_ajax_added_to_cart' , $product_id );
2018-02-22 15:37:01 +00:00
if ( 'yes' === get_option ( 'woocommerce_cart_redirect_after_add' ) ) {
2016-01-20 11:32:49 +00:00
wc_add_to_cart_message ( array ( $product_id => $quantity ), true );
2013-11-14 12:13:34 +00:00
}
2014-05-28 13:52:50 +00:00
self :: get_refreshed_fragments ();
2013-11-14 12:13:34 +00:00
} else {
2019-02-15 17:09:45 +00:00
// If there was an error adding to the cart, redirect to the product page to show any errors.
2013-11-14 12:13:34 +00:00
$data = array (
2015-01-29 18:30:07 +00:00
'error' => true ,
2016-08-27 01:46:45 +00:00
'product_url' => apply_filters ( 'woocommerce_cart_redirect_after_error' , get_permalink ( $product_id ), $product_id ),
2013-11-14 12:13:34 +00:00
);
2014-05-31 07:32:22 +00:00
wp_send_json ( $data );
2013-11-14 12:13:34 +00:00
}
2019-02-15 17:09:45 +00:00
// phpcs:enable
2013-11-14 12:13:34 +00:00
}
2017-07-13 11:15:13 +00:00
/**
2017-11-22 12:33:21 +00:00
* AJAX remove from cart .
2017-07-13 11:15:13 +00:00
*/
public static function remove_from_cart () {
ob_start ();
2019-11-20 16:16:19 +00:00
// phpcs:ignore WordPress.Security.NonceVerification.Missing
2019-02-15 17:09:45 +00:00
$cart_item_key = wc_clean ( isset ( $_POST [ 'cart_item_key' ] ) ? wp_unslash ( $_POST [ 'cart_item_key' ] ) : '' );
2017-07-13 11:15:13 +00:00
if ( $cart_item_key && false !== WC () -> cart -> remove_cart_item ( $cart_item_key ) ) {
self :: get_refreshed_fragments ();
} else {
wp_send_json_error ();
}
}
2013-11-14 12:13:34 +00:00
/**
2015-11-03 13:31:20 +00:00
* Process ajax checkout form .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function checkout () {
2016-11-24 14:20:58 +00:00
wc_maybe_define_constant ( 'WOOCOMMERCE_CHECKOUT' , true );
2014-05-28 13:52:50 +00:00
WC () -> checkout () -> process_checkout ();
2017-01-29 20:43:25 +00:00
wp_die ( 0 );
2013-11-14 12:13:34 +00:00
}
2015-07-09 14:56:20 +00:00
/**
2015-11-03 13:31:20 +00:00
* Get a matching variation based on posted attributes .
2015-07-09 14:56:20 +00:00
*/
public static function get_variation () {
ob_start ();
2019-11-20 16:16:19 +00:00
// phpcs:disable WordPress.Security.NonceVerification.Missing
2019-02-15 17:09:45 +00:00
if ( empty ( $_POST [ 'product_id' ] ) ) {
wp_die ();
}
$variable_product = wc_get_product ( absint ( $_POST [ 'product_id' ] ) );
if ( ! $variable_product ) {
2017-01-29 20:43:25 +00:00
wp_die ();
2015-07-09 14:56:20 +00:00
}
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$data_store = WC_Data_Store :: load ( 'product' );
$variation_id = $data_store -> find_matching_product_variation ( $variable_product , wp_unslash ( $_POST ) );
2016-11-24 15:31:05 +00:00
$variation = $variation_id ? $variable_product -> get_available_variation ( $variation_id ) : false ;
2015-07-09 14:56:20 +00:00
wp_send_json ( $variation );
2019-02-15 17:09:45 +00:00
// phpcs:enable
2015-07-09 14:56:20 +00:00
}
2016-11-24 11:50:58 +00:00
/**
* Locate user via AJAX .
*/
public static function get_customer_location () {
$location_hash = WC_Cache_Helper :: geolocation_ajax_get_location_hash ();
wp_send_json_success ( array ( 'hash' => $location_hash ) );
}
2013-11-14 12:13:34 +00:00
/**
2016-11-23 06:47:26 +00:00
* Toggle Featured status of a product from admin .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function feature_product () {
2019-02-15 17:09:45 +00:00
if ( current_user_can ( 'edit_products' ) && check_admin_referer ( 'woocommerce-feature-product' ) && isset ( $_GET [ 'product_id' ] ) ) {
2016-11-24 11:50:58 +00:00
$product = wc_get_product ( absint ( $_GET [ 'product_id' ] ) );
2013-11-14 12:13:34 +00:00
2016-11-24 11:50:58 +00:00
if ( $product ) {
2016-11-23 06:47:26 +00:00
$product -> set_featured ( ! $product -> get_featured () );
$product -> save ();
2014-11-27 15:40:39 +00:00
}
2014-04-04 13:16:11 +00:00
}
2013-11-14 12:13:34 +00:00
2016-04-18 10:48:57 +00:00
wp_safe_redirect ( wp_get_referer () ? remove_query_arg ( array ( 'trashed' , 'untrashed' , 'deleted' , 'ids' ), wp_get_referer () ) : admin_url ( 'edit.php?post_type=product' ) );
2018-05-23 13:50:49 +00:00
exit ;
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Mark an order with a status .
2013-11-14 12:13:34 +00:00
*/
2014-11-19 12:13:24 +00:00
public static function mark_order_status () {
2019-02-15 17:09:45 +00:00
if ( current_user_can ( 'edit_shop_orders' ) && check_admin_referer ( 'woocommerce-mark-order-status' ) && isset ( $_GET [ 'status' ], $_GET [ 'order_id' ] ) ) {
$status = sanitize_text_field ( wp_unslash ( $_GET [ 'status' ] ) );
$order = wc_get_order ( absint ( wp_unslash ( $_GET [ 'order_id' ] ) ) );
2014-05-12 13:04:36 +00:00
2016-11-24 11:50:58 +00:00
if ( wc_is_order_status ( 'wc-' . $status ) && $order ) {
2017-09-25 21:37:13 +00:00
// Initialize payment gateways in case order has hooked status transition actions.
2018-11-08 10:59:07 +00:00
WC () -> payment_gateways ();
2017-09-25 21:37:13 +00:00
2015-10-01 14:15:29 +00:00
$order -> update_status ( $status , '' , true );
2017-01-03 23:08:37 +00:00
do_action ( 'woocommerce_order_edit_status' , $order -> get_id (), $status );
2014-11-27 15:37:42 +00:00
}
2014-05-12 13:04:36 +00:00
}
2013-11-14 12:13:34 +00:00
2014-10-23 11:13:42 +00:00
wp_safe_redirect ( wp_get_referer () ? wp_get_referer () : admin_url ( 'edit.php?post_type=shop_order' ) );
2018-05-23 13:50:49 +00:00
exit ;
2013-11-14 12:13:34 +00:00
}
2017-09-04 16:42:31 +00:00
/**
* Get order details .
*/
public static function get_order_details () {
check_admin_referer ( 'woocommerce-preview-order' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_GET [ 'order_id' ] ) ) {
2017-09-04 16:42:31 +00:00
wp_die ( - 1 );
}
2020-10-01 08:53:38 +00:00
$order = wc_get_order ( absint ( $_GET [ 'order_id' ] ) );
2017-09-04 16:42:31 +00:00
2017-11-20 22:43:37 +00:00
if ( $order ) {
2020-08-26 20:50:34 +00:00
include_once __DIR__ . '/admin/list-tables/class-wc-admin-list-table-orders.php' ;
2017-09-04 16:42:31 +00:00
2017-11-21 16:22:43 +00:00
wp_send_json_success ( WC_Admin_List_Table_Orders :: order_preview_get_order_details ( $order ) );
2017-09-04 16:42:31 +00:00
}
2018-02-26 17:27:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
2014-12-22 14:16:12 +00:00
/**
2015-11-03 13:31:20 +00:00
* Add an attribute row .
2014-12-22 14:16:12 +00:00
*/
public static function add_attribute () {
ob_start ();
check_ajax_referer ( 'add-attribute' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_products' ) || ! isset ( $_POST [ 'taxonomy' ], $_POST [ 'i' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2015-01-19 13:38:47 +00:00
$i = absint ( $_POST [ 'i' ] );
$metabox_class = array ();
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$attribute = new WC_Product_Attribute ();
2014-12-22 14:16:12 +00:00
2019-02-15 17:09:45 +00:00
$attribute -> set_id ( wc_attribute_taxonomy_id_by_name ( sanitize_text_field ( wp_unslash ( $_POST [ 'taxonomy' ] ) ) ) );
$attribute -> set_name ( sanitize_text_field ( wp_unslash ( $_POST [ 'taxonomy' ] ) ) );
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$attribute -> set_visible ( apply_filters ( 'woocommerce_attribute_default_visibility' , 1 ) );
$attribute -> set_variation ( apply_filters ( 'woocommerce_attribute_default_is_variation' , 0 ) );
if ( $attribute -> is_taxonomy () ) {
$metabox_class [] = 'taxonomy' ;
$metabox_class [] = $attribute -> get_name ();
2014-12-22 14:16:12 +00:00
}
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-product-attribute.php' ;
2017-01-29 20:43:25 +00:00
wp_die ();
2014-12-22 14:16:12 +00:00
}
2013-11-14 12:13:34 +00:00
/**
2015-11-03 13:31:20 +00:00
* Add a new attribute via ajax function .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function add_new_attribute () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'add-attribute' , 'security' );
2019-02-15 17:09:45 +00:00
if ( current_user_can ( 'manage_product_terms' ) && isset ( $_POST [ 'taxonomy' ], $_POST [ 'term' ] ) ) {
$taxonomy = esc_attr ( wp_unslash ( $_POST [ 'taxonomy' ] ) ); // phpcs:ignore
$term = wc_clean ( wp_unslash ( $_POST [ 'term' ] ) );
2016-11-24 11:50:58 +00:00
if ( taxonomy_exists ( $taxonomy ) ) {
$result = wp_insert_term ( $term , $taxonomy );
if ( is_wp_error ( $result ) ) {
2018-02-22 15:37:01 +00:00
wp_send_json (
array (
'error' => $result -> get_error_message (),
)
);
2016-11-24 11:50:58 +00:00
} else {
$term = get_term_by ( 'id' , $result [ 'term_id' ], $taxonomy );
2018-02-22 15:37:01 +00:00
wp_send_json (
array (
'term_id' => $term -> term_id ,
'name' => $term -> name ,
'slug' => $term -> slug ,
)
);
2016-11-24 11:50:58 +00:00
}
2013-11-14 12:13:34 +00:00
}
}
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Delete variations via ajax function .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function remove_variations () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'delete-variations' , 'security' );
2014-05-12 13:04:36 +00:00
2019-02-15 17:09:45 +00:00
if ( current_user_can ( 'edit_products' ) && isset ( $_POST [ 'variation_ids' ] ) ) {
$variation_ids = array_map ( 'absint' , ( array ) wp_unslash ( $_POST [ 'variation_ids' ] ) );
2014-05-12 13:04:36 +00:00
2016-11-24 11:50:58 +00:00
foreach ( $variation_ids as $variation_id ) {
if ( 'product_variation' === get_post_type ( $variation_id ) ) {
$variation = wc_get_product ( $variation_id );
2017-01-04 14:05:13 +00:00
$variation -> delete ( true );
2016-11-24 11:50:58 +00:00
}
2014-05-12 13:04:36 +00:00
}
2013-11-14 12:13:34 +00:00
}
2014-05-12 13:04:36 +00:00
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Save attributes via ajax .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function save_attributes () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'save-attributes' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_products' ) || ! isset ( $_POST [ 'data' ], $_POST [ 'post_id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-01-07 13:29:09 +00:00
$response = array ();
2017-11-17 15:43:14 +00:00
try {
2019-02-15 17:09:45 +00:00
parse_str ( wp_unslash ( $_POST [ 'data' ] ), $data ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2017-01-05 16:54:47 +00:00
2017-11-17 15:43:14 +00:00
$attributes = WC_Meta_Box_Product_Data :: prepare_attributes ( $data );
2019-02-15 17:09:45 +00:00
$product_id = absint ( wp_unslash ( $_POST [ 'post_id' ] ) );
$product_type = ! empty ( $_POST [ 'product_type' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'product_type' ] ) ) : 'simple' ;
2017-11-17 15:43:14 +00:00
$classname = WC_Product_Factory :: get_product_classname ( $product_id , $product_type );
$product = new $classname ( $product_id );
2013-11-14 12:13:34 +00:00
2017-11-17 15:43:14 +00:00
$product -> set_attributes ( $attributes );
$product -> save ();
ob_start ();
$attributes = $product -> get_attributes ( 'edit' );
$i = - 1 ;
2019-02-27 11:56:00 +00:00
if ( ! empty ( $data [ 'attribute_names' ] ) ) {
2019-02-22 13:43:35 +00:00
foreach ( $data [ 'attribute_names' ] as $attribute_name ) {
$attribute = isset ( $attributes [ sanitize_title ( $attribute_name ) ] ) ? $attributes [ sanitize_title ( $attribute_name ) ] : false ;
if ( ! $attribute ) {
continue ;
}
$i ++ ;
$metabox_class = array ();
2017-11-17 15:43:14 +00:00
2019-02-22 13:43:35 +00:00
if ( $attribute -> is_taxonomy () ) {
$metabox_class [] = 'taxonomy' ;
$metabox_class [] = $attribute -> get_name ();
}
2017-11-17 15:43:14 +00:00
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-product-attribute.php' ;
2017-11-17 15:43:14 +00:00
}
}
$response [ 'html' ] = ob_get_clean ();
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2018-09-28 11:42:51 +00:00
wp_send_json_success ( $response );
2013-11-14 12:13:34 +00:00
}
/**
2016-11-23 06:47:26 +00:00
* Add variation via ajax function .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function add_variation () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'add-variation' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_products' ) || ! isset ( $_POST [ 'post_id' ], $_POST [ 'loop' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2017-11-08 13:12:54 +00:00
global $post ; // Set $post global so its available, like within the admin screens.
2013-11-14 12:13:34 +00:00
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$product_id = intval ( $_POST [ 'post_id' ] );
2019-02-15 17:09:45 +00:00
$post = get_post ( $product_id ); // phpcs:ignore
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$loop = intval ( $_POST [ 'loop' ] );
2019-12-04 19:15:16 +00:00
$product_object = wc_get_product_object ( 'variable' , $product_id ); // Forces type to variable in case product is unsaved.
$variation_object = wc_get_product_object ( 'variation' );
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$variation_object -> set_parent_id ( $product_id );
2017-11-18 13:55:26 +00:00
$variation_object -> set_attributes ( array_fill_keys ( array_map ( 'sanitize_title' , array_keys ( $product_object -> get_variation_attributes () ) ), '' ) );
2018-02-22 15:37:01 +00:00
$variation_id = $variation_object -> save ();
$variation = get_post ( $variation_id );
2019-01-21 16:02:28 +00:00
$variation_data = array_merge ( get_post_custom ( $variation_id ), wc_get_product_variation_attributes ( $variation_id ) ); // kept for BW compatibility.
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-variation-admin.php' ;
2017-01-29 20:43:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
/**
2016-11-24 15:31:05 +00:00
* Link all variations via ajax function .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function link_all_variations () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'link-variations' , 'security' );
2015-05-29 13:55:26 +00:00
if ( ! current_user_can ( 'edit_products' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-04-15 10:59:57 +00:00
wc_maybe_define_constant ( 'WC_MAX_LINKED_VARIATIONS' , 50 );
2016-06-06 15:55:27 +00:00
wc_set_time_limit ( 0 );
2013-11-14 12:13:34 +00:00
2019-02-15 17:09:45 +00:00
$post_id = isset ( $_POST [ 'post_id' ] ) ? intval ( $_POST [ 'post_id' ] ) : 0 ;
2013-11-14 12:13:34 +00:00
2014-05-12 13:04:36 +00:00
if ( ! $post_id ) {
2017-01-29 20:43:25 +00:00
wp_die ();
2014-05-12 13:04:36 +00:00
}
2013-11-14 12:13:34 +00:00
2016-11-24 14:20:58 +00:00
$product = wc_get_product ( $post_id );
2019-04-15 10:59:57 +00:00
$data_store = $product -> get_data_store ();
2016-12-08 14:28:51 +00:00
2019-04-15 10:59:57 +00:00
if ( ! is_callable ( array ( $data_store , 'create_all_product_variations' ) ) ) {
wp_die ();
2013-11-14 12:13:34 +00:00
}
2017-01-05 16:17:46 +00:00
2020-02-01 06:18:47 +00:00
echo esc_html ( $data_store -> create_all_product_variations ( $product , Constants :: get_constant ( 'WC_MAX_LINKED_VARIATIONS' ) ) );
2019-04-15 10:59:57 +00:00
2017-01-05 16:17:46 +00:00
$data_store -> sort_all_product_variations ( $product -> get_id () );
2017-01-29 20:43:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Delete download permissions via ajax function .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function revoke_access_to_download () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'revoke-access' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'download_id' ], $_POST [ 'product_id' ], $_POST [ 'order_id' ], $_POST [ 'permission_id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-02-15 17:09:45 +00:00
$download_id = wc_clean ( wp_unslash ( $_POST [ 'download_id' ] ) );
2016-07-14 13:54:28 +00:00
$product_id = intval ( $_POST [ 'product_id' ] );
$order_id = intval ( $_POST [ 'order_id' ] );
$permission_id = absint ( $_POST [ 'permission_id' ] );
2016-11-18 17:13:02 +00:00
$data_store = WC_Data_Store :: load ( 'customer-download' );
$data_store -> delete_by_id ( $permission_id );
2013-11-14 12:13:34 +00:00
2016-07-14 13:54:28 +00:00
do_action ( 'woocommerce_ajax_revoke_access_to_product_download' , $download_id , $product_id , $order_id , $permission_id );
2013-11-14 12:13:34 +00:00
2017-01-29 20:43:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Grant download permissions via ajax function .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function grant_access_to_download () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'grant-access' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'loop' ], $_POST [ 'order_id' ], $_POST [ 'product_ids' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2013-11-14 12:13:34 +00:00
global $wpdb ;
$wpdb -> hide_errors ();
2014-05-12 13:04:36 +00:00
$order_id = intval ( $_POST [ 'order_id' ] );
2019-02-15 17:09:45 +00:00
$product_ids = array_filter ( array_map ( 'absint' , ( array ) wp_unslash ( $_POST [ 'product_ids' ] ) ) );
2014-05-12 13:04:36 +00:00
$loop = intval ( $_POST [ 'loop' ] );
$file_counter = 0 ;
2014-08-15 12:29:21 +00:00
$order = wc_get_order ( $order_id );
2013-11-14 12:13:34 +00:00
2021-05-13 16:48:49 +00:00
if ( ! $order -> get_billing_email () ) {
wp_die ();
}
$data = array ();
$items = $order -> get_items ();
// Check against order items first.
2020-10-18 11:25:02 +00:00
foreach ( $items as $item ) {
$product = $item -> get_product ();
2021-05-13 16:48:49 +00:00
if ( $product && $product -> exists () && in_array ( $product -> get_id (), $product_ids , true ) && $product -> is_downloadable () ) {
$data [ $product -> get_id () ] = array (
'files' => $product -> get_downloads (),
'quantity' => $item -> get_quantity (),
'order_item' => $item ,
);
2020-10-18 11:25:02 +00:00
}
2021-05-13 16:48:49 +00:00
}
foreach ( $product_ids as $product_id ) {
$product = wc_get_product ( $product_id );
2013-11-14 12:13:34 +00:00
2021-05-13 16:48:49 +00:00
if ( isset ( $data [ $product -> get_id () ] ) ) {
$download_data = $data [ $product -> get_id () ];
} else {
$download_data = array (
'files' => $product -> get_downloads (),
'quantity' => 1 ,
'order_item' => null ,
);
2014-05-12 13:04:36 +00:00
}
2013-11-14 12:13:34 +00:00
2021-05-13 16:48:49 +00:00
if ( ! empty ( $download_data [ 'files' ] ) ) {
foreach ( $download_data [ 'files' ] as $download_id => $file ) {
$inserted_id = wc_downloadable_file_permission ( $download_id , $product -> get_id (), $order , $download_data [ 'quantity' ], $download_data [ 'order_item' ] );
2019-02-15 17:09:45 +00:00
if ( $inserted_id ) {
2016-11-18 17:13:02 +00:00
$download = new WC_Customer_Download ( $inserted_id );
2013-11-26 13:54:34 +00:00
$loop ++ ;
$file_counter ++ ;
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
if ( $file -> get_name () ) {
$file_count = $file -> get_name ();
2013-11-26 13:54:34 +00:00
} else {
2018-12-14 18:13:08 +00:00
/* translators: %d file count */
2013-11-26 13:54:34 +00:00
$file_count = sprintf ( __ ( 'File %d' , 'woocommerce' ), $file_counter );
}
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-download-permission.php' ;
2013-11-26 13:54:34 +00:00
}
2013-11-14 12:13:34 +00:00
}
}
}
2017-01-29 20:43:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get customer details via ajax .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function get_customer_details () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'get-customer-details' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'user_id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2016-12-20 16:02:33 +00:00
$user_id = absint ( $_POST [ 'user_id' ] );
$customer = new WC_Customer ( $user_id );
if ( has_filter ( 'woocommerce_found_customer_details' ) ) {
2017-04-03 05:59:04 +00:00
wc_deprecated_function ( 'The woocommerce_found_customer_details filter' , '3.0' , 'woocommerce_ajax_get_customer_details' );
2016-12-20 16:02:33 +00:00
}
2018-02-22 15:37:01 +00:00
$data = $customer -> get_data ();
2017-03-10 23:13:56 +00:00
$data [ 'date_created' ] = $data [ 'date_created' ] ? $data [ 'date_created' ] -> getTimestamp () : null ;
$data [ 'date_modified' ] = $data [ 'date_modified' ] ? $data [ 'date_modified' ] -> getTimestamp () : null ;
2017-04-03 06:00:07 +00:00
$customer_data = apply_filters ( 'woocommerce_ajax_get_customer_details' , $data , $customer , $user_id );
2014-05-31 07:32:22 +00:00
wp_send_json ( $customer_data );
2013-11-14 12:13:34 +00:00
}
/**
2019-03-05 13:31:14 +00:00
* Add order item via ajax . Used on the edit order screen in WP Admin .
2019-02-15 17:09:45 +00:00
*
* @ throws Exception If order is invalid .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function add_order_item () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'order-item' , 'security' );
2015-05-29 13:55:26 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2020-05-29 19:58:52 +00:00
if ( ! isset ( $_POST [ 'order_id' ] ) ) {
throw new Exception ( __ ( 'Invalid order' , 'woocommerce' ) );
}
$order_id = absint ( wp_unslash ( $_POST [ 'order_id' ] ) );
// If we passed through items it means we need to save first before adding a new one.
$items = ( ! empty ( $_POST [ 'items' ] ) ) ? wp_unslash ( $_POST [ 'items' ] ) : '' ; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$items_to_add = isset ( $_POST [ 'data' ] ) ? array_filter ( wp_unslash ( ( array ) $_POST [ 'data' ] ) ) : array (); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2019-01-07 13:29:09 +00:00
2016-08-24 15:02:19 +00:00
try {
2020-05-29 19:58:52 +00:00
$response = self :: maybe_add_order_item ( $order_id , $items , $items_to_add );
wp_send_json_success ( $response );
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
}
2018-06-08 15:18:32 +00:00
2020-05-29 19:58:52 +00:00
/**
* Add order item via AJAX . This is refactored for better unit testing .
*
* @ param int $order_id ID of order to add items to .
* @ param string | array $items Existing items in order . Empty string if no items to add .
* @ param array $items_to_add Array of items to add .
*
* @ return array Fragments to render and notes HTML .
* @ throws Exception When unable to add item .
*/
private static function maybe_add_order_item ( $order_id , $items , $items_to_add ) {
try {
$order = wc_get_order ( $order_id );
2013-11-14 12:13:34 +00:00
2017-02-23 10:19:32 +00:00
if ( ! $order ) {
throw new Exception ( __ ( 'Invalid order' , 'woocommerce' ) );
2016-08-24 15:02:19 +00:00
}
2013-11-14 12:13:34 +00:00
2017-10-27 11:38:10 +00:00
if ( ! empty ( $items ) ) {
$save_items = array ();
parse_str ( $items , $save_items );
wc_save_order_items ( $order -> get_id (), $save_items );
}
2018-06-08 15:18:32 +00:00
// Add items to order.
2019-01-03 12:23:49 +00:00
$order_notes = array ();
2021-09-20 14:06:41 +00:00
$added_items = array ();
2019-01-03 12:23:49 +00:00
2018-06-08 15:18:32 +00:00
foreach ( $items_to_add as $item ) {
if ( ! isset ( $item [ 'id' ], $item [ 'qty' ] ) || empty ( $item [ 'id' ] ) ) {
2017-02-23 10:19:32 +00:00
continue ;
}
2018-06-08 15:18:32 +00:00
$product_id = absint ( $item [ 'id' ] );
$qty = wc_stock_amount ( $item [ 'qty' ] );
$product = wc_get_product ( $product_id );
2018-05-02 11:49:24 +00:00
2018-06-08 15:18:32 +00:00
if ( ! $product ) {
throw new Exception ( __ ( 'Invalid product ID' , 'woocommerce' ) . ' ' . $product_id );
}
2019-11-30 01:06:50 +00:00
if ( 'variable' === $product -> get_type () ) {
/* translators: %s product name */
throw new Exception ( sprintf ( __ ( '%s is a variable product parent and cannot be added.' , 'woocommerce' ), $product -> get_name () ) );
}
2019-10-02 19:01:09 +00:00
$validation_error = new WP_Error ();
$validation_error = apply_filters ( 'woocommerce_ajax_add_order_item_validation' , $validation_error , $product , $order , $qty );
2018-05-02 11:49:24 +00:00
2019-10-02 19:01:09 +00:00
if ( $validation_error -> get_error_code () ) {
2020-10-01 08:53:38 +00:00
/* translators: %s: error message */
2020-05-23 00:14:43 +00:00
throw new Exception ( sprintf ( __ ( 'Error: %s' , 'woocommerce' ), $validation_error -> get_error_message () ) );
2019-08-28 12:00:24 +00:00
}
2021-09-10 09:37:22 +00:00
$item_id = $order -> add_product ( $product , $qty , array ( 'order' => $order ) );
2019-07-09 12:31:47 +00:00
$item = apply_filters ( 'woocommerce_ajax_order_item' , $order -> get_item ( $item_id ), $item_id , $order , $product );
2018-05-02 11:49:24 +00:00
$added_items [ $item_id ] = $item ;
2019-01-03 12:23:49 +00:00
$order_notes [ $item_id ] = $product -> get_formatted_name ();
2020-05-29 19:58:52 +00:00
// We do not perform any stock operations here because they will be handled when order is moved to a status where stock operations are applied (like processing, completed etc).
2018-05-02 11:49:24 +00:00
2017-08-22 12:19:20 +00:00
do_action ( 'woocommerce_ajax_add_order_item_meta' , $item_id , $item , $order );
2017-02-23 10:19:32 +00:00
}
2016-08-25 13:22:27 +00:00
2019-01-03 12:23:49 +00:00
/* translators: %s item name. */
$order -> add_order_note ( sprintf ( __ ( 'Added line items: %s' , 'woocommerce' ), implode ( ', ' , $order_notes ) ), false , true );
2018-05-02 11:49:24 +00:00
do_action ( 'woocommerce_ajax_order_items_added' , $added_items , $order );
2017-08-22 12:19:20 +00:00
$data = get_post_meta ( $order_id );
2019-01-03 12:23:49 +00:00
// Get HTML to return.
2017-08-22 12:19:20 +00:00
ob_start ();
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2019-01-03 12:23:49 +00:00
$items_html = ob_get_clean ();
ob_start ();
$notes = wc_get_order_notes ( array ( 'order_id' => $order_id ) );
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-notes.php' ;
2019-01-03 12:23:49 +00:00
$notes_html = ob_get_clean ();
2020-05-29 19:58:52 +00:00
return array (
'html' => $items_html ,
'notes_html' => $notes_html ,
2018-02-22 15:37:01 +00:00
);
2016-08-25 13:22:27 +00:00
} catch ( Exception $e ) {
2020-05-29 19:58:52 +00:00
throw $e ; // Forward exception to caller.
2016-08-25 13:22:27 +00:00
}
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Add order fee via ajax .
2019-02-15 17:09:45 +00:00
*
* @ throws Exception If order is invalid .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function add_order_fee () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'order-item' , 'security' );
2015-05-29 13:55:26 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-01-07 13:29:09 +00:00
$response = array ();
2016-08-24 15:02:19 +00:00
try {
2019-02-15 17:09:45 +00:00
$order_id = isset ( $_POST [ 'order_id' ] ) ? absint ( $_POST [ 'order_id' ] ) : 0 ;
$order = wc_get_order ( $order_id );
2017-08-23 10:22:18 +00:00
if ( ! $order ) {
2019-02-15 17:09:45 +00:00
throw new Exception ( __ ( 'Invalid order' , 'woocommerce' ) );
2017-08-23 10:22:18 +00:00
}
2019-02-15 17:09:45 +00:00
$amount = isset ( $_POST [ 'amount' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'amount' ] ) ) : 0 ;
$calculate_tax_args = array (
2019-03-06 12:08:07 +00:00
'country' => isset ( $_POST [ 'country' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'country' ] ) ) ) : '' ,
'state' => isset ( $_POST [ 'state' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'state' ] ) ) ) : '' ,
'postcode' => isset ( $_POST [ 'postcode' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'postcode' ] ) ) ) : '' ,
'city' => isset ( $_POST [ 'city' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'city' ] ) ) ) : '' ,
2019-02-15 17:09:45 +00:00
);
2017-08-23 10:22:18 +00:00
if ( strstr ( $amount , '%' ) ) {
2021-05-19 18:47:30 +00:00
// We need to calculate totals first, so that $order->get_total() is correct.
$order -> calculate_totals ( false );
2017-08-23 10:22:18 +00:00
$formatted_amount = $amount ;
$percent = floatval ( trim ( $amount , '%' ) );
$amount = $order -> get_total () * ( $percent / 100 );
} else {
$amount = floatval ( $amount );
$formatted_amount = wc_price ( $amount , array ( 'currency' => $order -> get_currency () ) );
}
$fee = new WC_Order_Item_Fee ();
2017-08-23 11:15:06 +00:00
$fee -> set_amount ( $amount );
2017-08-23 10:22:18 +00:00
$fee -> set_total ( $amount );
2018-12-14 18:13:08 +00:00
/* translators: %s fee amount */
2018-11-02 18:49:30 +00:00
$fee -> set_name ( sprintf ( __ ( '%s fee' , 'woocommerce' ), wc_clean ( $formatted_amount ) ) );
2017-08-23 10:22:18 +00:00
$order -> add_item ( $fee );
2017-11-02 17:31:03 +00:00
$order -> calculate_taxes ( $calculate_tax_args );
$order -> calculate_totals ( false );
2017-08-23 10:22:18 +00:00
$order -> save ();
2013-11-14 12:13:34 +00:00
2016-08-25 13:22:27 +00:00
ob_start ();
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2018-09-28 11:42:51 +00:00
$response [ 'html' ] = ob_get_clean ();
2016-08-25 13:22:27 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2018-09-28 11:42:51 +00:00
wp_send_json_success ( $response );
2013-11-14 12:13:34 +00:00
}
2014-07-16 18:41:18 +00:00
/**
2015-11-03 13:31:20 +00:00
* Add order shipping cost via ajax .
2019-02-15 17:09:45 +00:00
*
* @ throws Exception If order is invalid .
2014-07-16 18:41:18 +00:00
*/
public static function add_order_shipping () {
check_ajax_referer ( 'order-item' , 'security' );
2015-05-29 13:55:26 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-01-07 13:29:09 +00:00
$response = array ();
2016-08-24 15:02:19 +00:00
try {
2019-02-15 17:09:45 +00:00
$order_id = isset ( $_POST [ 'order_id' ] ) ? absint ( $_POST [ 'order_id' ] ) : 0 ;
$order = wc_get_order ( $order_id );
if ( ! $order ) {
throw new Exception ( __ ( 'Invalid order' , 'woocommerce' ) );
}
2016-08-24 15:02:19 +00:00
$order_taxes = $order -> get_taxes ();
2018-10-02 15:03:17 +00:00
$shipping_methods = WC () -> shipping () ? WC () -> shipping () -> load_shipping_methods () : array ();
2014-07-24 20:55:25 +00:00
2019-02-15 17:09:45 +00:00
// Add new shipping.
2016-08-24 15:02:19 +00:00
$item = new WC_Order_Item_Shipping ();
$item -> set_shipping_rate ( new WC_Shipping_Rate () );
2016-11-18 13:20:59 +00:00
$item -> set_order_id ( $order_id );
$item_id = $item -> save ();
2014-07-16 18:41:18 +00:00
2016-08-25 13:22:27 +00:00
ob_start ();
2020-08-26 22:02:07 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-shipping.php' ;
2018-09-28 11:42:51 +00:00
$response [ 'html' ] = ob_get_clean ();
2016-08-25 13:22:27 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2018-09-28 11:42:51 +00:00
wp_send_json_success ( $response );
2014-07-16 18:41:18 +00:00
}
2014-07-21 01:36:12 +00:00
/**
2015-11-03 13:31:20 +00:00
* Add order tax column via ajax .
2019-02-15 17:09:45 +00:00
*
2019-03-05 13:05:55 +00:00
* @ throws Exception If order or tax rate is invalid .
2014-07-21 01:36:12 +00:00
*/
public static function add_order_tax () {
check_ajax_referer ( 'order-item' , 'security' );
2015-05-29 13:55:26 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-01-07 13:29:09 +00:00
$response = array ();
2016-08-24 15:02:19 +00:00
try {
2019-02-15 17:09:45 +00:00
$order_id = isset ( $_POST [ 'order_id' ] ) ? absint ( $_POST [ 'order_id' ] ) : 0 ;
2016-08-24 15:02:19 +00:00
$order = wc_get_order ( $order_id );
2019-02-15 17:09:45 +00:00
if ( ! $order ) {
throw new Exception ( __ ( 'Invalid order' , 'woocommerce' ) );
}
$rate_id = isset ( $_POST [ 'rate_id' ] ) ? absint ( $_POST [ 'rate_id' ] ) : '' ;
if ( ! $rate_id ) {
throw new Exception ( __ ( 'Invalid rate' , 'woocommerce' ) );
}
$data = get_post_meta ( $order_id );
// Add new tax.
2016-08-24 15:02:19 +00:00
$item = new WC_Order_Item_Tax ();
$item -> set_rate ( $rate_id );
$item -> set_order_id ( $order_id );
$item -> save ();
2014-07-21 01:36:12 +00:00
2016-08-25 13:22:27 +00:00
ob_start ();
2020-08-26 22:02:07 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2018-09-28 11:42:51 +00:00
$response [ 'html' ] = ob_get_clean ();
2016-08-25 13:22:27 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2018-09-28 11:42:51 +00:00
wp_send_json_success ( $response );
2014-07-21 01:36:12 +00:00
}
2017-08-09 13:54:30 +00:00
/**
* Add order discount via ajax .
2019-02-15 17:09:45 +00:00
*
2019-03-05 13:05:55 +00:00
* @ throws Exception If order or coupon is invalid .
2017-08-09 13:54:30 +00:00
*/
2017-08-18 09:59:55 +00:00
public static function add_coupon_discount () {
2017-08-09 13:54:30 +00:00
check_ajax_referer ( 'order-item' , 'security' );
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
wp_die ( - 1 );
}
2019-01-07 13:29:09 +00:00
$response = array ();
2017-08-09 13:54:30 +00:00
try {
2019-03-06 12:08:07 +00:00
$order_id = isset ( $_POST [ 'order_id' ] ) ? absint ( $_POST [ 'order_id' ] ) : 0 ;
2019-02-21 16:23:20 +00:00
$order = wc_get_order ( $order_id );
$calculate_tax_args = array (
2019-03-06 12:08:07 +00:00
'country' => isset ( $_POST [ 'country' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'country' ] ) ) ) : '' ,
'state' => isset ( $_POST [ 'state' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'state' ] ) ) ) : '' ,
'postcode' => isset ( $_POST [ 'postcode' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'postcode' ] ) ) ) : '' ,
'city' => isset ( $_POST [ 'city' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'city' ] ) ) ) : '' ,
2019-02-21 16:23:20 +00:00
);
2019-02-15 17:09:45 +00:00
if ( ! $order ) {
throw new Exception ( __ ( 'Invalid order' , 'woocommerce' ) );
}
if ( empty ( $_POST [ 'coupon' ] ) ) {
throw new Exception ( __ ( 'Invalid coupon' , 'woocommerce' ) );
}
2019-05-27 14:45:29 +00:00
// Add user ID and/or email so validation for coupon limits works.
$user_id_arg = isset ( $_POST [ 'user_id' ] ) ? absint ( $_POST [ 'user_id' ] ) : 0 ;
$user_email_arg = isset ( $_POST [ 'user_email' ] ) ? sanitize_email ( wp_unslash ( $_POST [ 'user_email' ] ) ) : '' ;
2019-03-08 16:14:49 +00:00
if ( $user_id_arg ) {
$order -> set_customer_id ( $user_id_arg );
}
2019-05-27 14:45:29 +00:00
if ( $user_email_arg ) {
$order -> set_billing_email ( $user_email_arg );
}
2019-03-08 16:14:49 +00:00
2019-11-20 16:16:19 +00:00
$result = $order -> apply_coupon ( wc_format_coupon_code ( wp_unslash ( $_POST [ 'coupon' ] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2017-08-09 13:54:30 +00:00
2017-09-27 11:50:20 +00:00
if ( is_wp_error ( $result ) ) {
2019-01-11 16:50:44 +00:00
throw new Exception ( html_entity_decode ( wp_strip_all_tags ( $result -> get_error_message () ) ) );
2017-09-27 11:50:20 +00:00
}
2017-08-09 13:54:30 +00:00
2019-02-21 16:23:20 +00:00
$order -> calculate_taxes ( $calculate_tax_args );
$order -> calculate_totals ( false );
2017-08-09 13:54:30 +00:00
ob_start ();
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2018-09-28 11:42:51 +00:00
$response [ 'html' ] = ob_get_clean ();
2017-08-09 13:54:30 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2018-09-28 11:42:51 +00:00
wp_send_json_success ( $response );
2017-08-09 13:54:30 +00:00
}
2017-08-09 21:55:35 +00:00
/**
* Remove coupon from an order via ajax .
2019-02-15 17:09:45 +00:00
*
2019-03-05 13:05:55 +00:00
* @ throws Exception If order or coupon is invalid .
2017-08-09 21:55:35 +00:00
*/
public static function remove_order_coupon () {
check_ajax_referer ( 'order-item' , 'security' );
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
wp_die ( - 1 );
}
2019-01-07 13:29:09 +00:00
$response = array ();
2017-08-09 21:55:35 +00:00
try {
2019-03-06 12:08:07 +00:00
$order_id = isset ( $_POST [ 'order_id' ] ) ? absint ( $_POST [ 'order_id' ] ) : 0 ;
2019-02-21 16:23:20 +00:00
$order = wc_get_order ( $order_id );
$calculate_tax_args = array (
2019-03-06 12:08:07 +00:00
'country' => isset ( $_POST [ 'country' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'country' ] ) ) ) : '' ,
'state' => isset ( $_POST [ 'state' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'state' ] ) ) ) : '' ,
'postcode' => isset ( $_POST [ 'postcode' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'postcode' ] ) ) ) : '' ,
'city' => isset ( $_POST [ 'city' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'city' ] ) ) ) : '' ,
2019-02-21 16:23:20 +00:00
);
2017-08-09 21:55:35 +00:00
2019-02-15 17:09:45 +00:00
if ( ! $order ) {
throw new Exception ( __ ( 'Invalid order' , 'woocommerce' ) );
}
if ( empty ( $_POST [ 'coupon' ] ) ) {
throw new Exception ( __ ( 'Invalid coupon' , 'woocommerce' ) );
}
2019-11-20 16:16:19 +00:00
$order -> remove_coupon ( wc_format_coupon_code ( wp_unslash ( $_POST [ 'coupon' ] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2019-02-21 16:23:20 +00:00
$order -> calculate_taxes ( $calculate_tax_args );
$order -> calculate_totals ( false );
2017-08-09 21:55:35 +00:00
ob_start ();
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2018-09-28 11:42:51 +00:00
$response [ 'html' ] = ob_get_clean ();
2017-08-09 21:55:35 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2018-09-28 11:42:51 +00:00
wp_send_json_success ( $response );
2017-08-09 21:55:35 +00:00
}
2013-11-14 12:13:34 +00:00
/**
2015-11-03 13:31:20 +00:00
* Remove an order item .
2019-02-15 17:09:45 +00:00
*
* @ throws Exception If order is invalid .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function remove_order_item () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'order-item' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'order_id' ], $_POST [ 'order_item_ids' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-01-07 13:29:09 +00:00
$response = array ();
2017-08-10 15:32:24 +00:00
try {
2019-01-03 12:23:49 +00:00
$order_id = absint ( $_POST [ 'order_id' ] );
$order = wc_get_order ( $order_id );
if ( ! $order ) {
throw new Exception ( __ ( 'Invalid order' , 'woocommerce' ) );
}
if ( ! isset ( $_POST [ 'order_item_ids' ] ) ) {
throw new Exception ( __ ( 'Invalid items' , 'woocommerce' ) );
}
2019-02-15 17:09:45 +00:00
$order_item_ids = wp_unslash ( $_POST [ 'order_item_ids' ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$items = ( ! empty ( $_POST [ 'items' ] ) ) ? wp_unslash ( $_POST [ 'items' ] ) : '' ; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2017-11-02 17:31:03 +00:00
$calculate_tax_args = array (
2019-03-06 12:08:07 +00:00
'country' => isset ( $_POST [ 'country' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'country' ] ) ) ) : '' ,
'state' => isset ( $_POST [ 'state' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'state' ] ) ) ) : '' ,
'postcode' => isset ( $_POST [ 'postcode' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'postcode' ] ) ) ) : '' ,
'city' => isset ( $_POST [ 'city' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'city' ] ) ) ) : '' ,
2017-11-02 17:31:03 +00:00
);
2013-11-14 12:13:34 +00:00
2017-08-10 15:32:24 +00:00
if ( ! is_array ( $order_item_ids ) && is_numeric ( $order_item_ids ) ) {
$order_item_ids = array ( $order_item_ids );
}
2014-07-07 15:45:08 +00:00
2017-10-20 18:51:16 +00:00
// If we passed through items it means we need to save first before deleting.
if ( ! empty ( $items ) ) {
$save_items = array ();
parse_str ( $items , $save_items );
2019-01-03 12:23:49 +00:00
wc_save_order_items ( $order -> get_id (), $save_items );
2017-10-20 18:51:16 +00:00
}
2019-01-03 12:23:49 +00:00
if ( ! empty ( $order_item_ids ) ) {
foreach ( $order_item_ids as $item_id ) {
2019-03-05 13:31:14 +00:00
$item_id = absint ( $item_id );
$item = $order -> get_item ( $item_id );
2019-01-03 12:23:49 +00:00
// Before deleting the item, adjust any stock values already reduced.
if ( $item -> is_type ( 'line_item' ) ) {
2019-01-03 13:40:48 +00:00
$changed_stock = wc_maybe_adjust_line_item_product_stock ( $item , 0 );
2019-01-03 12:23:49 +00:00
2019-01-03 13:40:48 +00:00
if ( $changed_stock && ! is_wp_error ( $changed_stock ) ) {
2019-01-03 12:23:49 +00:00
/* translators: %1$s: item name %2$s: stock change */
2019-01-03 13:40:48 +00:00
$order -> add_order_note ( sprintf ( __ ( 'Deleted %1$s and adjusted stock (%2$s)' , 'woocommerce' ), $item -> get_name (), $changed_stock [ 'from' ] . '→' . $changed_stock [ 'to' ] ), false , true );
2019-01-03 12:23:49 +00:00
} else {
/* translators: %s item name. */
$order -> add_order_note ( sprintf ( __ ( 'Deleted %s' , 'woocommerce' ), $item -> get_name () ), false , true );
}
}
wc_delete_order_item ( $item_id );
2017-08-10 15:32:24 +00:00
}
2013-11-14 12:13:34 +00:00
}
2017-08-10 15:32:24 +00:00
$order = wc_get_order ( $order_id );
2017-11-02 17:31:03 +00:00
$order -> calculate_taxes ( $calculate_tax_args );
$order -> calculate_totals ( false );
2017-08-10 15:32:24 +00:00
2021-01-27 18:48:05 +00:00
/**
* Fires after order items are removed .
*
2021-02-26 23:54:40 +00:00
* @ since 5.2 . 0
2021-01-27 18:48:05 +00:00
*
* @ param int $item_id WC item ID .
* @ param WC_Order_Item | false $item As returned by $order -> get_item ( $item_id ) .
* @ param bool | array | WP_Error $changed_store Result of wc_maybe_adjust_line_item_product_stock () .
* @ param bool | WC_Order | WC_Order_Refund $order As returned by wc_get_order () .
*/
2020-12-18 18:04:05 +00:00
do_action ( 'woocommerce_ajax_order_items_removed' , $item_id , $item , $changed_stock , $order );
2019-01-03 12:23:49 +00:00
// Get HTML to return.
2017-08-10 15:32:24 +00:00
ob_start ();
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2019-01-03 12:23:49 +00:00
$items_html = ob_get_clean ();
ob_start ();
$notes = wc_get_order_notes ( array ( 'order_id' => $order_id ) );
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-notes.php' ;
2019-01-03 12:23:49 +00:00
$notes_html = ob_get_clean ();
2017-08-10 15:32:24 +00:00
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
2019-01-03 12:23:49 +00:00
'html' => $items_html ,
'notes_html' => $notes_html ,
2018-02-22 15:37:01 +00:00
)
);
2017-08-10 15:32:24 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
2013-11-14 12:13:34 +00:00
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2018-09-28 11:42:51 +00:00
wp_send_json_success ( $response );
2013-11-14 12:13:34 +00:00
}
2014-07-21 01:57:23 +00:00
/**
2015-11-03 13:31:20 +00:00
* Remove an order tax .
2019-02-15 17:09:45 +00:00
*
2019-03-05 13:05:55 +00:00
* @ throws Exception If there is an error whilst deleting the rate .
2014-07-21 01:57:23 +00:00
*/
2014-08-27 20:03:49 +00:00
public static function remove_order_tax () {
2014-07-21 01:57:23 +00:00
check_ajax_referer ( 'order-item' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'order_id' ], $_POST [ 'rate_id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-01-07 13:29:09 +00:00
$response = array ();
2017-08-10 15:32:24 +00:00
try {
$order_id = absint ( $_POST [ 'order_id' ] );
$rate_id = absint ( $_POST [ 'rate_id' ] );
2014-07-21 01:57:23 +00:00
2019-06-20 13:01:01 +00:00
$order = wc_get_order ( $order_id );
if ( ! $order -> is_editable () ) {
throw new Exception ( __ ( 'Order not editable' , 'woocommerce' ) );
}
2017-08-10 15:32:24 +00:00
wc_delete_order_item ( $rate_id );
2014-07-21 01:57:23 +00:00
2019-06-20 13:01:01 +00:00
// Need to load order again after deleting to have latest items before calculating.
2017-08-10 15:32:24 +00:00
$order = wc_get_order ( $order_id );
2017-08-15 13:51:12 +00:00
$order -> calculate_totals ( false );
2017-08-10 15:32:24 +00:00
ob_start ();
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2018-09-28 11:42:51 +00:00
$response [ 'html' ] = ob_get_clean ();
2017-08-10 15:32:24 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2018-09-28 11:42:51 +00:00
wp_send_json_success ( $response );
2014-07-21 01:57:23 +00:00
}
2016-03-22 17:13:39 +00:00
2013-11-14 12:13:34 +00:00
/**
2015-11-03 13:31:20 +00:00
* Calc line tax .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function calc_line_taxes () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'calc-totals' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'order_id' ], $_POST [ 'items' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2016-08-22 15:48:19 +00:00
$order_id = absint ( $_POST [ 'order_id' ] );
$calculate_tax_args = array (
2019-03-06 12:08:07 +00:00
'country' => isset ( $_POST [ 'country' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'country' ] ) ) ) : '' ,
'state' => isset ( $_POST [ 'state' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'state' ] ) ) ) : '' ,
'postcode' => isset ( $_POST [ 'postcode' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'postcode' ] ) ) ) : '' ,
'city' => isset ( $_POST [ 'city' ] ) ? wc_strtoupper ( wc_clean ( wp_unslash ( $_POST [ 'city' ] ) ) ) : '' ,
2016-08-22 15:48:19 +00:00
);
2015-10-05 14:31:58 +00:00
2019-02-15 17:09:45 +00:00
// Parse the jQuery serialized items.
2016-08-22 15:48:19 +00:00
$items = array ();
2019-02-15 17:09:45 +00:00
parse_str ( wp_unslash ( $_POST [ 'items' ] ), $items ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2014-07-24 21:09:13 +00:00
2019-02-15 17:09:45 +00:00
// Save order items first.
2014-07-24 20:33:26 +00:00
wc_save_order_items ( $order_id , $items );
2013-11-14 12:13:34 +00:00
2019-02-15 17:09:45 +00:00
// Grab the order and recalculate taxes.
2016-08-22 15:48:19 +00:00
$order = wc_get_order ( $order_id );
$order -> calculate_taxes ( $calculate_tax_args );
2017-04-18 18:44:42 +00:00
$order -> calculate_totals ( false );
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2017-01-29 20:43:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
2014-07-17 20:17:54 +00:00
/**
2015-11-03 13:31:20 +00:00
* Save order items via ajax .
2014-07-17 20:17:54 +00:00
*/
public static function save_order_items () {
check_ajax_referer ( 'order-item' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'order_id' ], $_POST [ 'items' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2016-11-24 15:31:05 +00:00
if ( isset ( $_POST [ 'order_id' ], $_POST [ 'items' ] ) ) {
2014-07-17 20:17:54 +00:00
$order_id = absint ( $_POST [ 'order_id' ] );
2019-02-15 17:09:45 +00:00
// Parse the jQuery serialized items.
2014-07-17 20:17:54 +00:00
$items = array ();
2019-02-15 17:09:45 +00:00
parse_str ( wp_unslash ( $_POST [ 'items' ] ), $items ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2014-07-17 20:17:54 +00:00
2019-02-15 17:09:45 +00:00
// Save order items.
2014-07-17 20:17:54 +00:00
wc_save_order_items ( $order_id , $items );
2019-02-15 17:09:45 +00:00
// Return HTML items.
2014-11-26 22:22:38 +00:00
$order = wc_get_order ( $order_id );
2019-01-03 13:40:48 +00:00
// Get HTML to return.
ob_start ();
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2019-01-03 13:40:48 +00:00
$items_html = ob_get_clean ();
ob_start ();
$notes = wc_get_order_notes ( array ( 'order_id' => $order_id ) );
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-notes.php' ;
2019-01-03 13:40:48 +00:00
$notes_html = ob_get_clean ();
wp_send_json_success (
array (
'html' => $items_html ,
'notes_html' => $notes_html ,
)
);
2014-07-17 20:17:54 +00:00
}
2017-01-29 20:43:25 +00:00
wp_die ();
2014-07-17 20:17:54 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Load order items via ajax .
2014-07-17 20:17:54 +00:00
*/
public static function load_order_items () {
check_ajax_referer ( 'order-item' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'order_id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-02-15 17:09:45 +00:00
// Return HTML items.
2014-07-17 20:17:54 +00:00
$order_id = absint ( $_POST [ 'order_id' ] );
2014-11-26 22:22:38 +00:00
$order = wc_get_order ( $order_id );
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-order-items.php' ;
2017-01-29 20:43:25 +00:00
wp_die ();
2014-07-17 20:17:54 +00:00
}
2013-11-14 12:13:34 +00:00
/**
2015-11-03 13:31:20 +00:00
* Add order note via ajax .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function add_order_note () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'add-order-note' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'post_id' ], $_POST [ 'note' ], $_POST [ 'note_type' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2015-03-03 16:36:47 +00:00
$post_id = absint ( $_POST [ 'post_id' ] );
2019-02-15 17:09:45 +00:00
$note = wp_kses_post ( trim ( wp_unslash ( $_POST [ 'note' ] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$note_type = wc_clean ( wp_unslash ( $_POST [ 'note_type' ] ) );
2013-11-14 12:13:34 +00:00
2016-09-07 22:32:24 +00:00
$is_customer_note = ( 'customer' === $note_type ) ? 1 : 0 ;
2013-11-14 12:13:34 +00:00
if ( $post_id > 0 ) {
2014-08-15 12:29:21 +00:00
$order = wc_get_order ( $post_id );
2015-04-17 10:23:09 +00:00
$comment_id = $order -> add_order_note ( $note , $is_customer_note , true );
2017-11-15 19:03:07 +00:00
$note = wc_get_order_note ( $comment_id );
2013-11-14 12:13:34 +00:00
2017-11-15 19:03:07 +00:00
$note_classes = array ( 'note' );
$note_classes [] = $is_customer_note ? 'customer-note' : '' ;
$note_classes = apply_filters ( 'woocommerce_order_note_class' , array_filter ( $note_classes ), $note );
?>
< li rel = " <?php echo absint( $note->id ); ?> " class = " <?php echo esc_attr( implode( ' ', $note_classes ) ); ?> " >
< div class = " note_content " >
2019-02-15 17:09:45 +00:00
< ? php echo wp_kses_post ( wpautop ( wptexturize ( make_clickable ( $note -> content ) ) ) ); ?>
2017-11-15 19:03:07 +00:00
</ div >
< p class = " meta " >
2019-02-15 17:09:45 +00:00
< abbr class = " exact-date " title = " <?php echo esc_attr( $note->date_created ->date( 'y-m-d h:i:s' ) ); ?> " >
2018-12-14 18:13:08 +00:00
< ? php
/* translators: $1: Date created, $2 Time created */
2019-02-15 17:09:45 +00:00
printf ( esc_html__ ( 'added on %1$s at %2$s' , 'woocommerce' ), esc_html ( $note -> date_created -> date_i18n ( wc_date_format () ) ), esc_html ( $note -> date_created -> date_i18n ( wc_time_format () ) ) );
2018-12-14 18:13:08 +00:00
?>
2017-11-15 19:03:07 +00:00
</ abbr >
< ? php
if ( 'system' !== $note -> added_by ) :
/* translators: %s: note author */
2019-02-15 17:09:45 +00:00
printf ( ' ' . esc_html__ ( 'by %s' , 'woocommerce' ), esc_html ( $note -> added_by ) );
2017-11-15 19:03:07 +00:00
endif ;
?>
2019-02-15 17:09:45 +00:00
< a href = " # " class = " delete_note " role = " button " >< ? php esc_html_e ( 'Delete note' , 'woocommerce' ); ?> </a>
2017-11-15 19:03:07 +00:00
</ p >
</ li >
< ? php
2013-11-14 12:13:34 +00:00
}
2017-01-29 20:43:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Delete order note via ajax .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function delete_order_note () {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'delete-order-note' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'note_id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2014-05-12 13:04:36 +00:00
$note_id = ( int ) $_POST [ 'note_id' ];
2013-11-14 12:13:34 +00:00
2014-05-12 13:04:36 +00:00
if ( $note_id > 0 ) {
2017-07-13 22:38:37 +00:00
wc_delete_order_note ( $note_id );
2014-05-12 13:04:36 +00:00
}
2017-01-29 20:43:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Search for products and echo json .
2013-11-14 12:13:34 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param string $term ( default : '' ) Term to search for .
* @ param bool $include_variations in search or not .
2013-11-14 12:13:34 +00:00
*/
2016-11-24 11:50:58 +00:00
public static function json_search_products ( $term = '' , $include_variations = false ) {
2013-11-14 12:13:34 +00:00
check_ajax_referer ( 'search-products' , 'security' );
2019-03-12 23:15:10 +00:00
if ( empty ( $term ) && isset ( $_GET [ 'term' ] ) ) {
$term = ( string ) wc_clean ( wp_unslash ( $_GET [ 'term' ] ) );
}
2013-11-14 12:13:34 +00:00
2014-05-12 13:04:36 +00:00
if ( empty ( $term ) ) {
2017-01-29 20:43:25 +00:00
wp_die ();
2014-05-12 13:04:36 +00:00
}
2013-11-14 12:13:34 +00:00
2018-06-09 16:22:26 +00:00
if ( ! empty ( $_GET [ 'limit' ] ) ) {
$limit = absint ( $_GET [ 'limit' ] );
} else {
$limit = absint ( apply_filters ( 'woocommerce_json_search_limit' , 30 ) );
}
2019-04-09 02:33:50 +00:00
$include_ids = ! empty ( $_GET [ 'include' ] ) ? array_map ( 'absint' , ( array ) wp_unslash ( $_GET [ 'include' ] ) ) : array ();
$exclude_ids = ! empty ( $_GET [ 'exclude' ] ) ? array_map ( 'absint' , ( array ) wp_unslash ( $_GET [ 'exclude' ] ) ) : array ();
2013-11-14 12:13:34 +00:00
2019-12-04 22:39:41 +00:00
$exclude_types = array ();
2019-12-03 22:14:47 +00:00
if ( ! empty ( $_GET [ 'exclude_type' ] ) ) {
2019-12-04 22:39:41 +00:00
// Support both comma-delimited and array format inputs.
$exclude_types = wp_unslash ( $_GET [ 'exclude_type' ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( ! is_array ( $exclude_types ) ) {
$exclude_types = explode ( ',' , $exclude_types );
}
2019-12-03 22:14:47 +00:00
// Sanitize the excluded types against valid product types.
2019-12-04 22:39:41 +00:00
foreach ( $exclude_types as & $exclude_type ) {
$exclude_type = strtolower ( trim ( $exclude_type ) );
}
$exclude_types = array_intersect (
array_merge ( array ( 'variation' ), array_keys ( wc_get_product_types () ) ),
$exclude_types
);
2019-12-03 22:14:47 +00:00
}
2019-04-09 02:33:50 +00:00
$data_store = WC_Data_Store :: load ( 'product' );
$ids = $data_store -> search_products ( $term , '' , ( bool ) $include_variations , false , $limit , $include_ids , $exclude_ids );
2015-12-12 12:28:45 +00:00
2020-11-03 12:53:19 +00:00
$products = array ();
2015-12-12 14:37:32 +00:00
2020-11-03 10:34:34 +00:00
foreach ( $ids as $id ) {
$product_object = wc_get_product ( $id );
2020-11-03 12:53:19 +00:00
2020-11-03 10:34:34 +00:00
if ( ! wc_products_array_filter_readable ( $product_object ) ) {
continue ;
}
2020-11-03 12:53:19 +00:00
2018-06-08 15:18:32 +00:00
$formatted_name = $product_object -> get_formatted_name ();
$managing_stock = $product_object -> managing_stock ();
2019-12-03 22:14:47 +00:00
if ( in_array ( $product_object -> get_type (), $exclude_types , true ) ) {
continue ;
}
2018-06-15 14:11:07 +00:00
if ( $managing_stock && ! empty ( $_GET [ 'display_stock' ] ) ) {
2020-10-01 08:53:38 +00:00
$stock_amount = $product_object -> get_stock_quantity ();
2019-03-12 14:48:05 +00:00
/* Translators: %d stock amount */
$formatted_name .= ' – ' . sprintf ( __ ( 'Stock: %d' , 'woocommerce' ), wc_format_stock_quantity_for_display ( $stock_amount , $product_object ) );
2018-06-08 15:18:32 +00:00
}
2020-11-25 21:15:56 +00:00
$products [ $product_object -> get_id () ] = rawurldecode ( wp_strip_all_tags ( $formatted_name ) );
2013-11-14 12:13:34 +00:00
}
2016-11-24 11:50:58 +00:00
wp_send_json ( apply_filters ( 'woocommerce_json_search_found_products' , $products ) );
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Search for product variations and return json .
2013-11-14 12:13:34 +00:00
*
* @ see WC_AJAX :: json_search_products ()
*/
2014-05-28 13:52:50 +00:00
public static function json_search_products_and_variations () {
2016-11-24 11:50:58 +00:00
self :: json_search_products ( '' , true );
2013-11-14 12:13:34 +00:00
}
2013-11-26 13:54:34 +00:00
/**
2015-11-03 13:31:20 +00:00
* Search for downloadable product variations and return json .
2013-11-26 13:54:34 +00:00
*
* @ see WC_AJAX :: json_search_products ()
*/
2014-05-28 13:52:50 +00:00
public static function json_search_downloadable_products_and_variations () {
2015-05-29 13:55:26 +00:00
check_ajax_referer ( 'search-products' , 'security' );
2019-04-09 02:41:49 +00:00
if ( ! empty ( $_GET [ 'limit' ] ) ) {
$limit = absint ( $_GET [ 'limit' ] );
} else {
$limit = absint ( apply_filters ( 'woocommerce_json_search_limit' , 30 ) );
2015-07-20 16:41:14 +00:00
}
2013-11-26 13:54:34 +00:00
2019-04-09 02:41:49 +00:00
$include_ids = ! empty ( $_GET [ 'include' ] ) ? array_map ( 'absint' , ( array ) wp_unslash ( $_GET [ 'include' ] ) ) : array ();
$exclude_ids = ! empty ( $_GET [ 'exclude' ] ) ? array_map ( 'absint' , ( array ) wp_unslash ( $_GET [ 'exclude' ] ) ) : array ();
2014-05-12 13:04:36 +00:00
2019-04-09 02:41:49 +00:00
$term = isset ( $_GET [ 'term' ] ) ? ( string ) wc_clean ( wp_unslash ( $_GET [ 'term' ] ) ) : '' ;
$data_store = WC_Data_Store :: load ( 'product' );
$ids = $data_store -> search_products ( $term , 'downloadable' , true , false , $limit );
2014-05-12 13:04:36 +00:00
2018-02-22 14:11:27 +00:00
$product_objects = array_filter ( array_map ( 'wc_get_product' , $ids ), 'wc_products_array_filter_readable' );
2016-11-24 11:50:58 +00:00
$products = array ();
2015-06-09 12:33:13 +00:00
2016-11-24 11:50:58 +00:00
foreach ( $product_objects as $product_object ) {
2021-07-18 11:59:33 +00:00
$products [ $product_object -> get_id () ] = rawurldecode ( wp_strip_all_tags ( $product_object -> get_formatted_name () ) );
2013-11-26 13:54:34 +00:00
}
2016-11-24 11:50:58 +00:00
wp_send_json ( $products );
2013-11-26 13:54:34 +00:00
}
2015-07-08 21:38:17 +00:00
/**
2015-11-03 13:31:20 +00:00
* Search for customers and return json .
2015-07-08 21:38:17 +00:00
*/
public static function json_search_customers () {
ob_start ();
check_ajax_referer ( 'search-customers' , 'security' );
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-07-08 21:38:17 +00:00
}
2019-02-15 17:09:45 +00:00
$term = isset ( $_GET [ 'term' ] ) ? ( string ) wc_clean ( wp_unslash ( $_GET [ 'term' ] ) ) : '' ;
2018-10-16 08:23:43 +00:00
$limit = 0 ;
2015-07-08 21:38:17 +00:00
if ( empty ( $term ) ) {
2017-01-29 20:43:25 +00:00
wp_die ();
2015-07-08 21:38:17 +00:00
}
2018-01-19 07:52:05 +00:00
$ids = array ();
2017-04-06 05:19:12 +00:00
// Search by ID.
if ( is_numeric ( $term ) ) {
$customer = new WC_Customer ( intval ( $term ) );
// Customer does not exists.
2018-01-19 07:52:05 +00:00
if ( 0 !== $customer -> get_id () ) {
$ids = array ( $customer -> get_id () );
2017-04-06 05:19:12 +00:00
}
2018-01-19 07:52:05 +00:00
}
2017-04-06 05:19:12 +00:00
2018-01-19 07:52:05 +00:00
// Usernames can be numeric so we first check that no users was found by ID before searching for numeric username, this prevents performance issues with ID lookups.
if ( empty ( $ids ) ) {
2017-04-06 05:19:12 +00:00
$data_store = WC_Data_Store :: load ( 'customer' );
2017-05-16 09:16:04 +00:00
// If search is smaller than 3 characters, limit result set to avoid
// too many rows being returned.
if ( 3 > strlen ( $term ) ) {
$limit = 20 ;
}
$ids = $data_store -> search_customers ( $term , $limit );
2017-04-06 05:19:12 +00:00
}
2018-01-19 07:57:27 +00:00
$found_customers = array ();
2015-07-08 21:38:17 +00:00
2016-11-24 15:31:05 +00:00
if ( ! empty ( $_GET [ 'exclude' ] ) ) {
2019-02-15 17:09:45 +00:00
$ids = array_diff ( $ids , array_map ( 'absint' , ( array ) wp_unslash ( $_GET [ 'exclude' ] ) ) );
2015-07-08 21:38:17 +00:00
}
2016-03-15 17:23:06 +00:00
2016-11-24 15:31:05 +00:00
foreach ( $ids as $id ) {
$customer = new WC_Customer ( $id );
/* translators: 1: user display name 2: user ID 3: user email */
$found_customers [ $id ] = sprintf (
2018-12-14 18:13:08 +00:00
/* translators: $1: customer name, $2 customer id, $3: customer email */
2016-11-24 15:31:05 +00:00
esc_html__ ( '%1$s (#%2$s – %3$s)' , 'woocommerce' ),
$customer -> get_first_name () . ' ' . $customer -> get_last_name (),
$customer -> get_id (),
$customer -> get_email ()
);
2014-08-21 17:00:39 +00:00
}
2013-11-14 12:13:34 +00:00
2016-11-24 15:31:05 +00:00
wp_send_json ( apply_filters ( 'woocommerce_json_search_found_customers' , $found_customers ) );
2013-11-14 12:13:34 +00:00
}
2017-07-13 16:04:40 +00:00
/**
* Search for categories and return json .
*/
public static function json_search_categories () {
ob_start ();
check_ajax_referer ( 'search-categories' , 'security' );
if ( ! current_user_can ( 'edit_products' ) ) {
wp_die ( - 1 );
}
2019-02-15 17:09:45 +00:00
$search_text = isset ( $_GET [ 'term' ] ) ? wc_clean ( wp_unslash ( $_GET [ 'term' ] ) ) : '' ;
if ( ! $search_text ) {
2017-07-13 16:04:40 +00:00
wp_die ();
}
$found_categories = array ();
$args = array (
'taxonomy' => array ( 'product_cat' ),
'orderby' => 'id' ,
'order' => 'ASC' ,
'hide_empty' => true ,
'fields' => 'all' ,
'name__like' => $search_text ,
);
2019-02-15 17:09:45 +00:00
$terms = get_terms ( $args );
if ( $terms ) {
2017-07-13 16:04:40 +00:00
foreach ( $terms as $term ) {
$term -> formatted_name = '' ;
if ( $term -> parent ) {
$ancestors = array_reverse ( get_ancestors ( $term -> term_id , 'product_cat' ) );
foreach ( $ancestors as $ancestor ) {
2019-02-15 17:09:45 +00:00
$ancestor_term = get_term ( $ancestor , 'product_cat' );
if ( $ancestor_term ) {
2017-07-13 16:04:40 +00:00
$term -> formatted_name .= $ancestor_term -> name . ' > ' ;
}
}
}
2018-02-22 15:37:01 +00:00
$term -> formatted_name .= $term -> name . ' (' . $term -> count . ')' ;
2017-07-13 16:04:40 +00:00
$found_categories [ $term -> term_id ] = $term ;
}
}
wp_send_json ( apply_filters ( 'woocommerce_json_search_found_categories' , $found_categories ) );
}
2021-02-19 23:28:07 +00:00
/**
* Ajax request handling for page searching .
*/
public static function json_search_pages () {
ob_start ();
check_ajax_referer ( 'search-pages' , 'security' );
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
wp_die ( - 1 );
}
$search_text = isset ( $_GET [ 'term' ] ) ? wc_clean ( wp_unslash ( $_GET [ 'term' ] ) ) : '' ;
$limit = isset ( $_GET [ 'limit' ] ) ? absint ( wp_unslash ( $_GET [ 'limit' ] ) ) : - 1 ;
$exclude_ids = ! empty ( $_GET [ 'exclude' ] ) ? array_map ( 'absint' , ( array ) wp_unslash ( $_GET [ 'exclude' ] ) ) : array ();
$args = array (
'no_found_rows' => true ,
'update_post_meta_cache' => false ,
'update_post_term_cache' => false ,
'posts_per_page' => $limit ,
'post_type' => 'page' ,
'post_status' => array ( 'publish' , 'private' , 'draft' ),
's' => $search_text ,
'post__not_in' => $exclude_ids ,
);
$search_results_query = new WP_Query ( $args );
$pages_results = array ();
foreach ( $search_results_query -> get_posts () as $post ) {
$pages_results [ $post -> ID ] = sprintf (
/* translators: 1: page name 2: page ID */
__ ( '%1$s (ID: %2$s)' , 'woocommerce' ),
get_the_title ( $post ),
$post -> ID
);
}
wp_send_json ( apply_filters ( 'woocommerce_json_search_found_pages' , $pages_results ) );
}
2013-11-14 12:13:34 +00:00
/**
2015-11-03 13:31:20 +00:00
* Ajax request handling for categories ordering .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function term_ordering () {
2019-11-20 16:16:19 +00:00
// phpcs:disable WordPress.Security.NonceVerification.Missing
2015-05-29 13:55:26 +00:00
if ( ! current_user_can ( 'edit_products' ) || empty ( $_POST [ 'id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2014-05-12 13:04:36 +00:00
$id = ( int ) $_POST [ 'id' ];
$next_id = isset ( $_POST [ 'nextid' ] ) && ( int ) $_POST [ 'nextid' ] ? ( int ) $_POST [ 'nextid' ] : null ;
2019-02-15 17:09:45 +00:00
$taxonomy = isset ( $_POST [ 'thetaxonomy' ] ) ? esc_attr ( wp_unslash ( $_POST [ 'thetaxonomy' ] ) ) : null ; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2015-05-29 13:55:26 +00:00
$term = get_term_by ( 'id' , $id , $taxonomy );
2013-11-14 12:13:34 +00:00
2014-05-12 13:04:36 +00:00
if ( ! $id || ! $term || ! $taxonomy ) {
2017-01-29 20:43:25 +00:00
wp_die ( 0 );
2014-05-12 13:04:36 +00:00
}
2013-11-14 12:13:34 +00:00
2013-12-05 16:07:44 +00:00
wc_reorder_terms ( $term , $next_id , $taxonomy );
2013-11-14 12:13:34 +00:00
2014-05-12 13:04:36 +00:00
$children = get_terms ( $taxonomy , " child_of= $id &menu_order=ASC&hide_empty=0 " );
2013-11-14 12:13:34 +00:00
2019-02-15 17:09:45 +00:00
if ( $term && count ( $children ) ) {
2013-11-14 12:13:34 +00:00
echo 'children' ;
2017-01-29 20:43:25 +00:00
wp_die ();
2013-11-14 12:13:34 +00:00
}
2019-02-15 17:09:45 +00:00
// phpcs:enable
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Ajax request handling for product ordering .
2013-11-14 12:13:34 +00:00
*
2016-10-11 23:37:15 +00:00
* Based on Simple Page Ordering by 10 up ( https :// wordpress . org / plugins / simple - page - ordering / ) .
2013-11-14 12:13:34 +00:00
*/
2014-05-28 13:52:50 +00:00
public static function product_ordering () {
2013-11-14 12:13:34 +00:00
global $wpdb ;
2019-11-20 16:16:19 +00:00
// phpcs:disable WordPress.Security.NonceVerification.Missing
2016-11-24 17:50:24 +00:00
if ( ! current_user_can ( 'edit_products' ) || empty ( $_POST [ 'id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2014-05-12 13:04:36 +00:00
}
2013-11-14 12:13:34 +00:00
2016-11-24 17:50:24 +00:00
$sorting_id = absint ( $_POST [ 'id' ] );
$previd = absint ( isset ( $_POST [ 'previd' ] ) ? $_POST [ 'previd' ] : 0 );
$nextid = absint ( isset ( $_POST [ 'nextid' ] ) ? $_POST [ 'nextid' ] : 0 );
$menu_orders = wp_list_pluck ( $wpdb -> get_results ( " SELECT ID, menu_order FROM { $wpdb -> posts } WHERE post_type = 'product' ORDER BY menu_order ASC, post_title ASC " ), 'menu_order' , 'ID' );
$index = 0 ;
2013-11-14 12:13:34 +00:00
2016-11-24 17:50:24 +00:00
foreach ( $menu_orders as $id => $menu_order ) {
$id = absint ( $id );
2013-11-14 12:13:34 +00:00
2016-11-24 17:50:24 +00:00
if ( $sorting_id === $id ) {
continue ;
2014-05-12 13:04:36 +00:00
}
2016-11-24 17:50:24 +00:00
if ( $nextid === $id ) {
$index ++ ;
2013-11-14 12:13:34 +00:00
}
2016-11-24 17:50:24 +00:00
$index ++ ;
$menu_orders [ $id ] = $index ;
$wpdb -> update ( $wpdb -> posts , array ( 'menu_order' => $index ), array ( 'ID' => $id ) );
2017-05-16 09:16:04 +00:00
2017-02-25 15:42:35 +00:00
/**
* When a single product has gotten it ' s ordering updated .
* $id The product ID
* $index The new menu order
*/
do_action ( 'woocommerce_after_single_product_ordering' , $id , $index );
2013-11-14 12:13:34 +00:00
}
2014-08-07 18:57:29 +00:00
2016-11-24 17:50:24 +00:00
if ( isset ( $menu_orders [ $previd ] ) ) {
$menu_orders [ $sorting_id ] = $menu_orders [ $previd ] + 1 ;
2016-12-05 14:21:09 +00:00
} elseif ( isset ( $menu_orders [ $nextid ] ) ) {
2016-11-24 17:50:24 +00:00
$menu_orders [ $sorting_id ] = $menu_orders [ $nextid ] - 1 ;
} else {
$menu_orders [ $sorting_id ] = 0 ;
}
$wpdb -> update ( $wpdb -> posts , array ( 'menu_order' => $menu_orders [ $sorting_id ] ), array ( 'ID' => $sorting_id ) );
2013-11-14 12:13:34 +00:00
2019-11-20 14:50:32 +00:00
WC_Post_Data :: delete_product_query_transients ();
2017-08-05 11:05:47 +00:00
do_action ( 'woocommerce_after_product_ordering' , $sorting_id , $menu_orders );
2016-11-24 17:50:24 +00:00
wp_send_json ( $menu_orders );
2019-02-15 17:09:45 +00:00
// phpcs:enable
2014-07-10 12:33:05 +00:00
}
/**
2016-11-24 17:50:24 +00:00
* Handle a refund via the edit order screen .
2017-09-28 15:17:13 +00:00
*
* @ throws Exception To return errors .
2014-07-10 12:33:05 +00:00
*/
public static function refund_line_items () {
2014-09-16 12:24:02 +00:00
ob_start ();
2014-07-10 12:33:05 +00:00
check_ajax_referer ( 'order-item' , 'security' );
2015-05-29 13:55:26 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-02-15 17:09:45 +00:00
$order_id = isset ( $_POST [ 'order_id' ] ) ? absint ( $_POST [ 'order_id' ] ) : 0 ;
$refund_amount = isset ( $_POST [ 'refund_amount' ] ) ? wc_format_decimal ( sanitize_text_field ( wp_unslash ( $_POST [ 'refund_amount' ] ) ), wc_get_price_decimals () ) : 0 ;
$refunded_amount = isset ( $_POST [ 'refunded_amount' ] ) ? wc_format_decimal ( sanitize_text_field ( wp_unslash ( $_POST [ 'refunded_amount' ] ) ), wc_get_price_decimals () ) : 0 ;
$refund_reason = isset ( $_POST [ 'refund_reason' ] ) ? sanitize_text_field ( wp_unslash ( $_POST [ 'refund_reason' ] ) ) : '' ;
$line_item_qtys = isset ( $_POST [ 'line_item_qtys' ] ) ? json_decode ( sanitize_text_field ( wp_unslash ( $_POST [ 'line_item_qtys' ] ) ), true ) : array ();
$line_item_totals = isset ( $_POST [ 'line_item_totals' ] ) ? json_decode ( sanitize_text_field ( wp_unslash ( $_POST [ 'line_item_totals' ] ) ), true ) : array ();
$line_item_tax_totals = isset ( $_POST [ 'line_item_tax_totals' ] ) ? json_decode ( sanitize_text_field ( wp_unslash ( $_POST [ 'line_item_tax_totals' ] ) ), true ) : array ();
$api_refund = isset ( $_POST [ 'api_refund' ] ) && 'true' === $_POST [ 'api_refund' ];
$restock_refunded_items = isset ( $_POST [ 'restock_refunded_items' ] ) && 'true' === $_POST [ 'restock_refunded_items' ];
2014-09-12 09:09:22 +00:00
$refund = false ;
2019-01-07 13:29:09 +00:00
$response = array ();
2014-05-31 07:32:22 +00:00
2014-07-10 13:49:04 +00:00
try {
2020-10-01 08:53:38 +00:00
$order = wc_get_order ( $order_id );
$max_refund = wc_format_decimal ( $order -> get_total () - $order -> get_total_refunded (), wc_get_price_decimals () );
2014-07-10 13:49:04 +00:00
2020-08-17 12:56:01 +00:00
if ( ( ! $refund_amount && ( wc_format_decimal ( 0 , wc_get_price_decimals () ) !== $refund_amount ) ) || $max_refund < $refund_amount || 0 > $refund_amount ) {
2019-02-15 17:09:45 +00:00
throw new Exception ( __ ( 'Invalid refund amount' , 'woocommerce' ) );
2014-07-10 13:49:04 +00:00
}
2014-07-16 18:41:18 +00:00
2019-02-15 17:09:45 +00:00
if ( wc_format_decimal ( $order -> get_total_refunded (), wc_get_price_decimals () ) !== $refunded_amount ) {
throw new Exception ( __ ( 'Error processing refund. Please try again.' , 'woocommerce' ) );
2017-09-28 15:17:13 +00:00
}
// Prepare line items which we are refunding.
2014-07-24 14:34:14 +00:00
$line_items = array ();
2019-03-05 14:51:58 +00:00
$item_ids = array_unique ( array_merge ( array_keys ( $line_item_qtys ), array_keys ( $line_item_totals ) ) );
2014-07-24 14:34:14 +00:00
foreach ( $item_ids as $item_id ) {
2018-02-22 15:37:01 +00:00
$line_items [ $item_id ] = array (
'qty' => 0 ,
'refund_total' => 0 ,
'refund_tax' => array (),
);
2014-07-24 14:34:14 +00:00
}
foreach ( $line_item_qtys as $item_id => $qty ) {
$line_items [ $item_id ][ 'qty' ] = max ( $qty , 0 );
}
foreach ( $line_item_totals as $item_id => $total ) {
2014-09-08 11:45:32 +00:00
$line_items [ $item_id ][ 'refund_total' ] = wc_format_decimal ( $total );
2014-07-24 14:34:14 +00:00
}
foreach ( $line_item_tax_totals as $item_id => $tax_totals ) {
2017-03-29 12:13:00 +00:00
$line_items [ $item_id ][ 'refund_tax' ] = array_filter ( array_map ( 'wc_format_decimal' , $tax_totals ) );
2014-07-24 14:34:14 +00:00
}
2017-02-08 16:20:42 +00:00
// Create the refund object.
2018-02-22 15:37:01 +00:00
$refund = wc_create_refund (
array (
'amount' => $refund_amount ,
'reason' => $refund_reason ,
'order_id' => $order_id ,
'line_items' => $line_items ,
'refund_payment' => $api_refund ,
'restock_items' => $restock_refunded_items ,
)
);
2014-07-10 13:49:04 +00:00
if ( is_wp_error ( $refund ) ) {
2014-08-07 18:57:29 +00:00
throw new Exception ( $refund -> get_error_message () );
2014-07-10 13:49:04 +00:00
}
2017-02-08 16:20:42 +00:00
if ( did_action ( 'woocommerce_order_fully_refunded' ) ) {
2019-01-07 13:29:09 +00:00
$response [ 'status' ] = 'fully_refunded' ;
2015-01-02 12:43:47 +00:00
}
2014-07-10 13:49:04 +00:00
} catch ( Exception $e ) {
2015-01-02 12:43:47 +00:00
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
2014-07-10 13:49:04 +00:00
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2019-01-07 13:29:09 +00:00
wp_send_json_success ( $response );
2013-11-14 12:13:34 +00:00
}
2014-07-10 15:39:10 +00:00
/**
2015-11-03 13:31:20 +00:00
* Delete a refund .
2014-07-10 15:39:10 +00:00
*/
public static function delete_refund () {
check_ajax_referer ( 'order-item' , 'security' );
2019-02-15 17:09:45 +00:00
if ( ! current_user_can ( 'edit_shop_orders' ) || ! isset ( $_POST [ 'refund_id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2019-02-15 17:09:45 +00:00
$refund_ids = array_map ( 'absint' , is_array ( $_POST [ 'refund_id' ] ) ? wp_unslash ( $_POST [ 'refund_id' ] ) : array ( wp_unslash ( $_POST [ 'refund_id' ] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2016-03-23 16:32:12 +00:00
foreach ( $refund_ids as $refund_id ) {
if ( $refund_id && 'shop_order_refund' === get_post_type ( $refund_id ) ) {
2016-11-24 15:31:05 +00:00
$refund = wc_get_order ( $refund_id );
$order_id = $refund -> get_parent_id ();
2017-01-04 14:05:13 +00:00
$refund -> delete ( true );
2016-03-23 16:32:12 +00:00
do_action ( 'woocommerce_refund_deleted' , $refund_id , $order_id );
}
2014-07-10 15:39:10 +00:00
}
2017-01-29 20:43:25 +00:00
wp_die ();
2014-07-10 15:39:10 +00:00
}
2015-02-19 11:38:35 +00:00
/**
* Triggered when clicking the rating footer .
*/
public static function rated () {
2015-05-29 13:55:26 +00:00
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-05-29 13:55:26 +00:00
}
2015-02-19 11:38:35 +00:00
update_option ( 'woocommerce_admin_footer_text_rated' , 1 );
2017-01-29 20:43:25 +00:00
wp_die ();
2015-02-19 11:38:35 +00:00
}
2015-06-08 22:41:35 +00:00
/**
2015-11-03 13:31:20 +00:00
* Create / Update API key .
2019-02-15 17:09:45 +00:00
*
2019-03-05 13:05:55 +00:00
* @ throws Exception On invalid or empty description , user , or permissions .
2015-06-08 22:41:35 +00:00
*/
public static function update_api_key () {
ob_start ();
global $wpdb ;
check_ajax_referer ( 'update-api-key' , 'security' );
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-06-08 22:41:35 +00:00
}
2019-01-07 13:29:09 +00:00
$response = array ();
2015-06-08 22:41:35 +00:00
try {
if ( empty ( $_POST [ 'description' ] ) ) {
throw new Exception ( __ ( 'Description is missing.' , 'woocommerce' ) );
}
if ( empty ( $_POST [ 'user' ] ) ) {
throw new Exception ( __ ( 'User is missing.' , 'woocommerce' ) );
}
if ( empty ( $_POST [ 'permissions' ] ) ) {
throw new Exception ( __ ( 'Permissions is missing.' , 'woocommerce' ) );
}
2019-02-15 17:09:45 +00:00
$key_id = isset ( $_POST [ 'key_id' ] ) ? absint ( $_POST [ 'key_id' ] ) : 0 ;
2015-09-07 15:29:03 +00:00
$description = sanitize_text_field ( wp_unslash ( $_POST [ 'description' ] ) );
2019-02-15 17:09:45 +00:00
$permissions = ( in_array ( wp_unslash ( $_POST [ 'permissions' ] ), array ( 'read' , 'write' , 'read_write' ), true ) ) ? sanitize_text_field ( wp_unslash ( $_POST [ 'permissions' ] ) ) : 'read' ;
2015-06-08 22:41:35 +00:00
$user_id = absint ( $_POST [ 'user' ] );
2018-10-17 23:01:36 +00:00
// Check if current user can edit other users.
if ( $user_id && ! current_user_can ( 'edit_user' , $user_id ) ) {
if ( get_current_user_id () !== $user_id ) {
throw new Exception ( __ ( 'You do not have permission to assign API Keys to the selected user.' , 'woocommerce' ) );
}
}
2015-06-08 22:41:35 +00:00
if ( 0 < $key_id ) {
$data = array (
'user_id' => $user_id ,
'description' => $description ,
2016-08-27 01:46:45 +00:00
'permissions' => $permissions ,
2015-06-08 22:41:35 +00:00
);
$wpdb -> update (
$wpdb -> prefix . 'woocommerce_api_keys' ,
$data ,
array ( 'key_id' => $key_id ),
array (
'%d' ,
'%s' ,
2016-08-27 02:08:49 +00:00
'%s' ,
2015-06-08 22:41:35 +00:00
),
array ( '%d' )
);
2019-01-07 13:29:09 +00:00
$response = $data ;
$response [ 'consumer_key' ] = '' ;
$response [ 'consumer_secret' ] = '' ;
$response [ 'message' ] = __ ( 'API Key updated successfully.' , 'woocommerce' );
2015-06-08 22:41:35 +00:00
} else {
$consumer_key = 'ck_' . wc_rand_hash ();
$consumer_secret = 'cs_' . wc_rand_hash ();
$data = array (
'user_id' => $user_id ,
'description' => $description ,
'permissions' => $permissions ,
'consumer_key' => wc_api_hash ( $consumer_key ),
2015-07-16 18:42:00 +00:00
'consumer_secret' => $consumer_secret ,
2016-08-27 01:46:45 +00:00
'truncated_key' => substr ( $consumer_key , - 7 ),
2015-06-08 22:41:35 +00:00
);
$wpdb -> insert (
$wpdb -> prefix . 'woocommerce_api_keys' ,
$data ,
array (
'%d' ,
'%s' ,
'%s' ,
'%s' ,
2015-07-16 18:42:00 +00:00
'%s' ,
2016-08-27 02:08:49 +00:00
'%s' ,
2015-06-08 22:41:35 +00:00
)
);
2019-01-07 13:29:09 +00:00
$key_id = $wpdb -> insert_id ;
$response = $data ;
$response [ 'consumer_key' ] = $consumer_key ;
$response [ 'consumer_secret' ] = $consumer_secret ;
$response [ 'message' ] = __ ( 'API Key generated successfully. Make sure to copy your new keys now as the secret key will be hidden once you leave this page.' , 'woocommerce' );
$response [ 'revoke_url' ] = '<a style="color: #a00; text-decoration: none;" href="' . esc_url ( wp_nonce_url ( add_query_arg ( array ( 'revoke-key' => $key_id ), admin_url ( 'admin.php?page=wc-settings&tab=advanced§ion=keys' ) ), 'revoke' ) ) . '">' . __ ( 'Revoke key' , 'woocommerce' ) . '</a>' ;
2015-06-08 22:41:35 +00:00
}
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'message' => $e -> getMessage () ) );
}
2018-09-28 11:42:51 +00:00
2018-10-04 18:22:18 +00:00
// wp_send_json_success must be outside the try block not to break phpunit tests.
2019-01-07 13:29:09 +00:00
wp_send_json_success ( $response );
2015-06-08 22:41:35 +00:00
}
2015-06-17 11:12:49 +00:00
2015-07-02 20:42:22 +00:00
/**
2015-11-03 13:31:20 +00:00
* Load variations via AJAX .
2015-07-02 20:42:22 +00:00
*/
public static function load_variations () {
ob_start ();
check_ajax_referer ( 'load-variations' , 'security' );
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
if ( ! current_user_can ( 'edit_products' ) || empty ( $_POST [ 'product_id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-07-02 20:42:22 +00:00
}
2019-02-15 17:09:45 +00:00
// Set $post global so its available, like within the admin screens.
2015-07-14 11:28:31 +00:00
global $post ;
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$loop = 0 ;
$product_id = absint ( $_POST [ 'product_id' ] );
2019-02-15 17:09:45 +00:00
$post = get_post ( $product_id ); // phpcs:ignore
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$product_object = wc_get_product ( $product_id );
$per_page = ! empty ( $_POST [ 'per_page' ] ) ? absint ( $_POST [ 'per_page' ] ) : 10 ;
$page = ! empty ( $_POST [ 'page' ] ) ? absint ( $_POST [ 'page' ] ) : 1 ;
2018-02-22 15:37:01 +00:00
$variations = wc_get_products (
array (
'status' => array ( 'private' , 'publish' ),
'type' => 'variation' ,
'parent' => $product_id ,
'limit' => $per_page ,
'page' => $page ,
'orderby' => array (
'menu_order' => 'ASC' ,
'ID' => 'DESC' ,
),
'return' => 'objects' ,
)
);
2015-07-02 20:42:22 +00:00
if ( $variations ) {
2019-03-25 13:30:04 +00:00
wc_render_invalid_variation_notice ( $product_object );
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
foreach ( $variations as $variation_object ) {
$variation_id = $variation_object -> get_id ();
$variation = get_post ( $variation_id );
2019-01-21 16:02:28 +00:00
$variation_data = array_merge ( get_post_custom ( $variation_id ), wc_get_product_variation_attributes ( $variation_id ) ); // kept for BW compatibility.
2020-08-26 20:50:34 +00:00
include __DIR__ . '/admin/meta-boxes/views/html-variation-admin.php' ;
2015-07-02 20:42:22 +00:00
$loop ++ ;
}
}
2017-01-29 20:43:25 +00:00
wp_die ();
2015-07-02 20:42:22 +00:00
}
2015-07-06 04:50:20 +00:00
/**
2015-11-03 13:31:20 +00:00
* Save variations via AJAX .
2015-07-06 04:50:20 +00:00
*/
public static function save_variations () {
ob_start ();
check_ajax_referer ( 'save-variations' , 'security' );
2019-02-15 17:09:45 +00:00
// Check permissions again and make sure we have what we need.
2015-07-08 16:55:29 +00:00
if ( ! current_user_can ( 'edit_products' ) || empty ( $_POST ) || empty ( $_POST [ 'product_id' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-07-06 04:50:20 +00:00
}
2018-02-22 15:37:01 +00:00
$product_id = absint ( $_POST [ 'product_id' ] );
2015-07-27 17:16:52 +00:00
WC_Admin_Meta_Boxes :: $meta_box_errors = array ();
2015-07-24 05:15:44 +00:00
WC_Meta_Box_Product_Data :: save_variations ( $product_id , get_post ( $product_id ) );
2015-07-06 22:07:01 +00:00
2015-07-09 20:43:46 +00:00
do_action ( 'woocommerce_ajax_save_product_variations' , $product_id );
2019-02-15 17:09:45 +00:00
$errors = WC_Admin_Meta_Boxes :: $meta_box_errors ;
if ( $errors ) {
2015-07-29 22:56:33 +00:00
echo '<div class="error notice is-dismissible">' ;
2015-07-27 17:16:52 +00:00
foreach ( $errors as $error ) {
echo '<p>' . wp_kses_post ( $error ) . '</p>' ;
}
2019-02-15 17:09:45 +00:00
echo '<button type="button" class="notice-dismiss"><span class="screen-reader-text">' . esc_html__ ( 'Dismiss this notice.' , 'woocommerce' ) . '</span></button>' ;
2015-07-27 17:16:52 +00:00
echo '</div>' ;
delete_option ( 'woocommerce_meta_box_errors' );
}
2017-01-29 20:43:25 +00:00
wp_die ();
2015-07-06 04:50:20 +00:00
}
2015-07-07 01:50:35 +00:00
/**
2016-11-24 15:31:05 +00:00
* Bulk action - Toggle Enabled .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-07 01:50:35 +00:00
*/
2015-07-14 10:39:48 +00:00
private static function variation_bulk_action_toggle_enabled ( $variations , $data ) {
foreach ( $variations as $variation_id ) {
2016-11-23 06:47:26 +00:00
$variation = wc_get_product ( $variation_id );
$variation -> set_status ( 'private' === $variation -> get_status ( 'edit' ) ? 'publish' : 'private' );
$variation -> save ();
2015-07-14 10:39:48 +00:00
}
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Toggle Downloadable Checkbox .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_toggle_downloadable ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_toggle ( $variations , 'downloadable' );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Toggle Virtual Checkbox .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_toggle_virtual ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_toggle ( $variations , 'virtual' );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Toggle Manage Stock Checkbox .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_toggle_manage_stock ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_toggle ( $variations , 'manage_stock' );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Set Regular Prices .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_regular_price ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_set ( $variations , 'regular_price' , $data [ 'value' ] );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Set Sale Prices .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_sale_price ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_set ( $variations , 'sale_price' , $data [ 'value' ] );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2017-04-06 20:11:04 +00:00
/**
* Bulk action - Set Stock Status as In Stock .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2017-04-06 20:11:04 +00:00
* @ used - by bulk_edit_variations
*/
private static function variation_bulk_action_variable_stock_status_instock ( $variations , $data ) {
self :: variation_bulk_set ( $variations , 'stock_status' , 'instock' );
}
/**
* Bulk action - Set Stock Status as Out of Stock .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2017-04-06 20:11:04 +00:00
* @ used - by bulk_edit_variations
*/
private static function variation_bulk_action_variable_stock_status_outofstock ( $variations , $data ) {
self :: variation_bulk_set ( $variations , 'stock_status' , 'outofstock' );
}
2017-11-14 22:18:03 +00:00
/**
* Bulk action - Set Stock Status as On Backorder .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2017-11-14 22:18:03 +00:00
* @ used - by bulk_edit_variations
*/
private static function variation_bulk_action_variable_stock_status_onbackorder ( $variations , $data ) {
self :: variation_bulk_set ( $variations , 'stock_status' , 'onbackorder' );
}
2015-07-14 10:39:48 +00:00
/**
2016-11-24 15:31:05 +00:00
* Bulk action - Set Stock .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_stock ( $variations , $data ) {
2015-08-21 15:48:25 +00:00
if ( ! isset ( $data [ 'value' ] ) ) {
2015-08-11 12:47:12 +00:00
return ;
2015-07-14 10:39:48 +00:00
}
2015-07-08 07:05:08 +00:00
2016-11-23 06:47:26 +00:00
$quantity = wc_stock_amount ( wc_clean ( $data [ 'value' ] ) );
2015-07-07 19:07:09 +00:00
2015-08-21 15:48:25 +00:00
foreach ( $variations as $variation_id ) {
2016-11-23 06:47:26 +00:00
$variation = wc_get_product ( $variation_id );
if ( $variation -> managing_stock () ) {
$variation -> set_stock_quantity ( $quantity );
2015-08-21 15:48:25 +00:00
} else {
2016-11-23 06:47:26 +00:00
$variation -> set_stock_quantity ( null );
2015-07-14 10:39:48 +00:00
}
2016-11-23 06:47:26 +00:00
$variation -> save ();
2015-07-14 10:39:48 +00:00
}
}
2015-07-07 01:50:35 +00:00
2021-03-10 17:15:31 +00:00
/**
* Bulk action - Set Low Stock Amount .
*
* @ param array $variations List of variations .
* @ param array $data Data to set .
*
* @ used - by bulk_edit_variations
*/
private static function variation_bulk_action_variable_low_stock_amount ( $variations , $data ) {
if ( ! isset ( $data [ 'value' ] ) ) {
return ;
}
$low_stock_amount = wc_stock_amount ( wc_clean ( $data [ 'value' ] ) );
foreach ( $variations as $variation_id ) {
$variation = wc_get_product ( $variation_id );
if ( $variation -> managing_stock () ) {
$variation -> set_low_stock_amount ( $low_stock_amount );
} else {
$variation -> set_low_stock_amount ( '' );
}
$variation -> save ();
}
}
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Set Weight .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_weight ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_set ( $variations , 'weight' , $data [ 'value' ] );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Set Length .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_length ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_set ( $variations , 'length' , $data [ 'value' ] );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Set Width .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_width ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_set ( $variations , 'width' , $data [ 'value' ] );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Set Height .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_height ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_set ( $variations , 'height' , $data [ 'value' ] );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Set Download Limit .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_download_limit ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_set ( $variations , 'download_limit' , $data [ 'value' ] );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Set Download Expiry .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_download_expiry ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_set ( $variations , 'download_expiry' , $data [ 'value' ] );
2015-07-14 10:39:48 +00:00
}
2015-07-07 20:35:21 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Delete all .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_delete_all ( $variations , $data ) {
if ( isset ( $data [ 'allowed' ] ) && 'true' === $data [ 'allowed' ] ) {
foreach ( $variations as $variation_id ) {
2016-11-23 06:47:26 +00:00
$variation = wc_get_product ( $variation_id );
2017-01-04 14:05:13 +00:00
$variation -> delete ( true );
2015-07-14 10:39:48 +00:00
}
}
}
2015-07-07 20:35:21 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Sale Schedule .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_sale_schedule ( $variations , $data ) {
if ( ! isset ( $data [ 'date_from' ] ) && ! isset ( $data [ 'date_to' ] ) ) {
2015-08-11 12:47:12 +00:00
return ;
2015-07-14 10:39:48 +00:00
}
2015-07-08 07:05:08 +00:00
2015-07-14 10:39:48 +00:00
foreach ( $variations as $variation_id ) {
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$variation = wc_get_product ( $variation_id );
2015-07-07 20:35:21 +00:00
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
if ( 'false' !== $data [ 'date_from' ] ) {
$variation -> set_date_on_sale_from ( wc_clean ( $data [ 'date_from' ] ) );
2015-07-14 10:39:48 +00:00
}
2015-07-07 20:35:21 +00:00
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
if ( 'false' !== $data [ 'date_to' ] ) {
2017-04-11 07:34:39 +00:00
$variation -> set_date_on_sale_to ( wc_clean ( $data [ 'date_to' ] ) );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$variation -> save ();
2015-07-14 10:39:48 +00:00
}
}
2015-07-07 19:39:59 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Increase Regular Prices .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_regular_price_increase ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_adjust_price ( $variations , 'regular_price' , '+' , wc_clean ( $data [ 'value' ] ) );
2015-07-14 10:39:48 +00:00
}
2015-07-08 07:05:08 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Decrease Regular Prices .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_regular_price_decrease ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_adjust_price ( $variations , 'regular_price' , '-' , wc_clean ( $data [ 'value' ] ) );
2015-07-14 10:39:48 +00:00
}
2015-07-08 07:05:08 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Increase Sale Prices .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_sale_price_increase ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_adjust_price ( $variations , 'sale_price' , '+' , wc_clean ( $data [ 'value' ] ) );
2015-07-14 10:39:48 +00:00
}
2015-07-08 07:05:08 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Decrease Sale Prices .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param array $data Data to set .
2018-12-14 18:13:08 +00:00
*
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_action_variable_sale_price_decrease ( $variations , $data ) {
2016-11-23 06:47:26 +00:00
self :: variation_bulk_adjust_price ( $variations , 'sale_price' , '-' , wc_clean ( $data [ 'value' ] ) );
2015-07-14 10:39:48 +00:00
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Bulk action - Set Price .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param string $field price being adjusted _regular_price or _sale_price .
* @ param string $operator + or -.
* @ param string $value Price or Percent .
2018-12-14 18:13:08 +00:00
*
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
*/
private static function variation_bulk_adjust_price ( $variations , $field , $operator , $value ) {
foreach ( $variations as $variation_id ) {
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$variation = wc_get_product ( $variation_id );
2016-11-23 06:47:26 +00:00
$field_value = $variation -> { " get_ $field " }( 'edit' );
2015-07-14 10:39:48 +00:00
if ( '%' === substr ( $value , - 1 ) ) {
2018-02-22 15:37:01 +00:00
$percent = wc_format_decimal ( substr ( $value , 0 , - 1 ) );
2020-10-01 08:57:12 +00:00
$field_value += NumberUtil :: round ( ( $field_value / 100 ) * $percent , wc_get_price_decimals () ) * " { $operator } 1 " ;
2015-07-14 10:39:48 +00:00
} else {
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$field_value += $value * " { $operator } 1 " ;
2015-07-14 10:39:48 +00:00
}
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
2016-11-23 06:47:26 +00:00
$variation -> { " set_ $field " }( $field_value );
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$variation -> save ();
2015-07-14 10:39:48 +00:00
}
}
2015-07-07 01:50:35 +00:00
2015-07-14 10:39:48 +00:00
/**
2016-11-23 06:47:26 +00:00
* Bulk set convenience function .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param string $field Field to set .
* @ param string $value to set .
2015-07-14 10:39:48 +00:00
*/
2016-11-23 06:47:26 +00:00
private static function variation_bulk_set ( $variations , $field , $value ) {
2015-07-14 10:39:48 +00:00
foreach ( $variations as $variation_id ) {
2016-11-23 06:47:26 +00:00
$variation = wc_get_product ( $variation_id );
$variation -> { " set_ $field " }( wc_clean ( $value ) );
$variation -> save ();
}
}
/**
* Bulk toggle convenience function .
2018-02-22 15:37:01 +00:00
*
2019-02-15 17:09:45 +00:00
* @ param array $variations List of variations .
* @ param string $field Field to toggle .
2016-11-23 06:47:26 +00:00
*/
private static function variation_bulk_toggle ( $variations , $field ) {
foreach ( $variations as $variation_id ) {
2018-02-22 15:37:01 +00:00
$variation = wc_get_product ( $variation_id );
2016-11-23 06:47:26 +00:00
$prev_value = $variation -> { " get_ $field " }( 'edit' );
$variation -> { " set_ $field " }( ! $prev_value );
$variation -> save ();
2015-07-14 10:39:48 +00:00
}
}
/**
2015-11-03 13:31:20 +00:00
* Bulk edit variations via AJAX .
2018-02-22 15:37:01 +00:00
*
2016-11-23 06:47:26 +00:00
* @ uses WC_AJAX :: variation_bulk_set ()
2016-06-07 13:19:36 +00:00
* @ 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
2021-03-10 17:15:31 +00:00
* @ uses WC_AJAX :: variation_bulk_action_variable_low_stock_amount ()
2015-07-14 10:39:48 +00:00
*/
public static function bulk_edit_variations () {
ob_start ();
check_ajax_referer ( 'bulk-edit-variations' , 'security' );
2019-02-15 17:09:45 +00:00
// Check permissions again and make sure we have what we need.
2015-07-14 10:39:48 +00:00
if ( ! current_user_can ( 'edit_products' ) || empty ( $_POST [ 'product_id' ] ) || empty ( $_POST [ 'bulk_action' ] ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2015-07-14 10:39:48 +00:00
}
$product_id = absint ( $_POST [ 'product_id' ] );
2019-02-15 17:09:45 +00:00
$bulk_action = wc_clean ( wp_unslash ( $_POST [ 'bulk_action' ] ) );
$data = ! empty ( $_POST [ 'data' ] ) ? wc_clean ( wp_unslash ( $_POST [ 'data' ] ) ) : array ();
2015-07-14 10:39:48 +00:00
$variations = array ();
if ( apply_filters ( 'woocommerce_bulk_edit_variations_need_children' , true ) ) {
2018-02-22 15:37:01 +00:00
$variations = get_posts (
array (
'post_parent' => $product_id ,
'posts_per_page' => - 1 ,
'post_type' => 'product_variation' ,
'fields' => 'ids' ,
'post_status' => array ( 'publish' , 'private' ),
)
);
2015-07-14 10:39:48 +00:00
}
if ( method_exists ( __CLASS__ , " variation_bulk_action_ $bulk_action " ) ) {
call_user_func ( array ( __CLASS__ , " variation_bulk_action_ $bulk_action " ), $variations , $data );
} else {
do_action ( 'woocommerce_bulk_edit_variations_default' , $bulk_action , $data , $product_id , $variations );
2015-07-07 01:50:35 +00:00
}
2015-07-07 19:39:59 +00:00
do_action ( 'woocommerce_bulk_edit_variations' , $bulk_action , $data , $product_id , $variations );
2015-07-07 01:50:35 +00:00
WC_Product_Variable :: sync ( $product_id );
wc_delete_product_transients ( $product_id );
2017-01-29 20:43:25 +00:00
wp_die ();
2015-07-07 01:50:35 +00:00
}
2015-08-13 21:49:59 +00:00
/**
* Handle submissions from assets / js / settings - views - html - settings - tax . js Backbone model .
*/
public static function tax_rates_save_changes () {
2019-11-20 16:16:19 +00:00
// phpcs:disable WordPress.Security.NonceVerification.Missing
2016-02-22 15:19:44 +00:00
if ( ! isset ( $_POST [ 'wc_tax_nonce' ], $_POST [ 'changes' ] ) ) {
2015-08-13 21:49:59 +00:00
wp_send_json_error ( 'missing_fields' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-08-13 21:49:59 +00:00
}
2019-02-15 17:09:45 +00:00
$current_class = ! empty ( $_POST [ 'current_class' ] ) ? wp_unslash ( $_POST [ 'current_class' ] ) : '' ; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2015-08-13 21:49:59 +00:00
2019-02-15 17:09:45 +00:00
if ( ! wp_verify_nonce ( wp_unslash ( $_POST [ 'wc_tax_nonce' ] ), 'wc_tax_nonce-class:' . $current_class ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2015-08-13 21:49:59 +00:00
wp_send_json_error ( 'bad_nonce' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-08-13 21:49:59 +00:00
}
$current_class = WC_Tax :: format_tax_rate_class ( $current_class );
2019-02-15 17:09:45 +00:00
// Check User Caps.
2015-08-13 21:49:59 +00:00
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
wp_send_json_error ( 'missing_capabilities' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-08-13 21:49:59 +00:00
}
2019-02-15 17:09:45 +00:00
$changes = wp_unslash ( $_POST [ 'changes' ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2015-08-13 21:49:59 +00:00
foreach ( $changes as $tax_rate_id => $data ) {
if ( isset ( $data [ 'deleted' ] ) ) {
if ( isset ( $data [ 'newRow' ] ) ) {
// So the user added and deleted a new row.
// That's fine, it's not in the database anyways. NEXT!
continue ;
}
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
}
2018-02-22 15:37:01 +00:00
$tax_rate = array_intersect_key (
2019-02-15 17:09:45 +00:00
$data ,
array (
2018-02-22 15:37:01 +00:00
'tax_rate_country' => 1 ,
'tax_rate_state' => 1 ,
'tax_rate' => 1 ,
'tax_rate_name' => 1 ,
'tax_rate_priority' => 1 ,
'tax_rate_compound' => 1 ,
'tax_rate_shipping' => 1 ,
'tax_rate_order' => 1 ,
)
);
2015-08-13 21:49:59 +00:00
2017-10-12 10:30:41 +00:00
if ( isset ( $tax_rate [ 'tax_rate' ] ) ) {
$tax_rate [ 'tax_rate' ] = wc_format_decimal ( $tax_rate [ 'tax_rate' ] );
}
2017-08-21 11:49:23 +00:00
2015-08-13 21:49:59 +00:00
if ( isset ( $data [ 'newRow' ] ) ) {
$tax_rate [ 'tax_rate_class' ] = $current_class ;
2017-10-12 10:30:41 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
} elseif ( ! empty ( $tax_rate ) ) {
WC_Tax :: _update_tax_rate ( $tax_rate_id , $tax_rate );
2015-08-13 21:49:59 +00:00
}
if ( isset ( $data [ 'postcode' ] ) ) {
2016-11-30 14:57:59 +00:00
$postcode = array_map ( 'wc_clean' , $data [ 'postcode' ] );
$postcode = array_map ( 'wc_normalize_postcode' , $postcode );
WC_Tax :: _update_tax_rate_postcodes ( $tax_rate_id , $postcode );
2015-08-13 21:49:59 +00:00
}
if ( isset ( $data [ 'city' ] ) ) {
2018-08-27 16:33:14 +00:00
WC_Tax :: _update_tax_rate_cities ( $tax_rate_id , array_map ( 'wc_clean' , array_map ( 'wp_unslash' , $data [ 'city' ] ) ) );
2015-08-13 21:49:59 +00:00
}
}
2019-11-28 13:03:57 +00:00
WC_Cache_Helper :: invalidate_cache_group ( 'taxes' );
2018-01-18 17:47:26 +00:00
WC_Cache_Helper :: get_transient_version ( 'shipping' , true );
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'rates' => WC_Tax :: get_rates_for_tax_class ( $current_class ),
)
);
2019-02-15 17:09:45 +00:00
// phpcs:enable
2015-08-13 21:49:59 +00:00
}
2015-12-10 11:55:03 +00:00
/**
* Handle submissions from assets / js / wc - shipping - zones . js Backbone model .
*/
public static function shipping_zones_save_changes () {
if ( ! isset ( $_POST [ 'wc_shipping_zones_nonce' ], $_POST [ 'changes' ] ) ) {
2015-12-15 17:48:03 +00:00
wp_send_json_error ( 'missing_fields' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-10 11:55:03 +00:00
}
2019-02-15 17:09:45 +00:00
if ( ! wp_verify_nonce ( wp_unslash ( $_POST [ 'wc_shipping_zones_nonce' ] ), 'wc_shipping_zones_nonce' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2015-12-10 11:55:03 +00:00
wp_send_json_error ( 'bad_nonce' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-10 11:55:03 +00:00
}
2019-02-15 17:09:45 +00:00
// Check User Caps.
2015-12-10 11:55:03 +00:00
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
wp_send_json_error ( 'missing_capabilities' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-10 11:55:03 +00:00
}
2019-02-15 17:09:45 +00:00
$changes = wp_unslash ( $_POST [ 'changes' ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2015-12-10 11:55:03 +00:00
foreach ( $changes as $zone_id => $data ) {
if ( isset ( $data [ 'deleted' ] ) ) {
if ( isset ( $data [ 'newRow' ] ) ) {
// So the user added and deleted a new row.
// That's fine, it's not in the database anyways. NEXT!
continue ;
}
WC_Shipping_Zones :: delete_zone ( $zone_id );
continue ;
}
2018-02-22 15:37:01 +00:00
$zone_data = array_intersect_key (
2019-02-15 17:09:45 +00:00
$data ,
array (
2018-02-22 15:37:01 +00:00
'zone_id' => 1 ,
'zone_order' => 1 ,
)
);
2015-12-10 11:55:03 +00:00
2015-12-10 12:31:03 +00:00
if ( isset ( $zone_data [ 'zone_id' ] ) ) {
$zone = new WC_Shipping_Zone ( $zone_data [ 'zone_id' ] );
if ( isset ( $zone_data [ 'zone_order' ] ) ) {
$zone -> set_zone_order ( $zone_data [ 'zone_order' ] );
}
$zone -> save ();
}
2015-12-10 11:55:03 +00:00
}
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
2018-05-09 16:41:33 +00:00
'zones' => WC_Shipping_Zones :: get_zones ( 'json' ),
2018-02-22 15:37:01 +00:00
)
);
2015-12-15 17:48:03 +00:00
}
2015-12-16 15:16:52 +00:00
/**
* Handle submissions from assets / js / wc - shipping - zone - methods . js Backbone model .
*/
public static function shipping_zone_add_method () {
if ( ! isset ( $_POST [ 'wc_shipping_zones_nonce' ], $_POST [ 'zone_id' ], $_POST [ 'method_id' ] ) ) {
wp_send_json_error ( 'missing_fields' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-16 15:16:52 +00:00
}
2019-02-15 17:09:45 +00:00
if ( ! wp_verify_nonce ( wp_unslash ( $_POST [ 'wc_shipping_zones_nonce' ] ), 'wc_shipping_zones_nonce' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2015-12-16 15:16:52 +00:00
wp_send_json_error ( 'bad_nonce' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-16 15:16:52 +00:00
}
2019-02-15 17:09:45 +00:00
// Check User Caps.
2015-12-16 15:16:52 +00:00
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
wp_send_json_error ( 'missing_capabilities' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-16 15:16:52 +00:00
}
2019-02-15 17:09:45 +00:00
$zone_id = wc_clean ( wp_unslash ( $_POST [ 'zone_id' ] ) );
2016-09-24 02:22:57 +00:00
$zone = new WC_Shipping_Zone ( $zone_id );
2019-02-15 17:09:45 +00:00
$instance_id = $zone -> add_shipping_method ( wc_clean ( wp_unslash ( $_POST [ 'method_id' ] ) ) );
2015-12-16 15:16:52 +00:00
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'instance_id' => $instance_id ,
'zone_id' => $zone -> get_id (),
'zone_name' => $zone -> get_zone_name (),
'methods' => $zone -> get_shipping_methods ( false , 'json' ),
)
);
2015-12-16 15:16:52 +00:00
}
2015-12-15 17:48:03 +00:00
/**
* Handle submissions from assets / js / wc - shipping - zone - methods . js Backbone model .
*/
public static function shipping_zone_methods_save_changes () {
2016-10-10 17:41:07 +00:00
if ( ! isset ( $_POST [ 'wc_shipping_zones_nonce' ], $_POST [ 'zone_id' ], $_POST [ 'changes' ] ) ) {
2015-12-15 17:48:03 +00:00
wp_send_json_error ( 'missing_fields' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-15 17:48:03 +00:00
}
2019-02-15 17:09:45 +00:00
if ( ! wp_verify_nonce ( wp_unslash ( $_POST [ 'wc_shipping_zones_nonce' ] ), 'wc_shipping_zones_nonce' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2015-12-15 17:48:03 +00:00
wp_send_json_error ( 'bad_nonce' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-15 17:48:03 +00:00
}
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
wp_send_json_error ( 'missing_capabilities' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-15 17:48:03 +00:00
}
global $wpdb ;
2019-02-15 17:09:45 +00:00
$zone_id = wc_clean ( wp_unslash ( $_POST [ 'zone_id' ] ) );
2015-12-15 17:48:03 +00:00
$zone = new WC_Shipping_Zone ( $zone_id );
2019-02-15 17:09:45 +00:00
$changes = wp_unslash ( $_POST [ 'changes' ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2016-09-24 02:22:57 +00:00
2016-10-10 17:41:07 +00:00
if ( isset ( $changes [ 'zone_name' ] ) ) {
$zone -> set_zone_name ( wc_clean ( $changes [ 'zone_name' ] ) );
2016-09-24 02:22:57 +00:00
}
2016-10-10 17:41:07 +00:00
if ( isset ( $changes [ 'zone_locations' ] ) ) {
2016-09-24 02:22:57 +00:00
$zone -> clear_locations ( array ( 'state' , 'country' , 'continent' ) );
2016-10-10 17:41:07 +00:00
$locations = array_filter ( array_map ( 'wc_clean' , ( array ) $changes [ 'zone_locations' ] ) );
2016-09-24 02:22:57 +00:00
foreach ( $locations as $location ) {
2019-02-15 17:09:45 +00:00
// Each posted location will be in the format type:code.
2016-09-24 02:22:57 +00:00
$location_parts = explode ( ':' , $location );
switch ( $location_parts [ 0 ] ) {
2018-02-22 15:37:01 +00:00
case 'state' :
2016-09-24 02:22:57 +00:00
$zone -> add_location ( $location_parts [ 1 ] . ':' . $location_parts [ 2 ], 'state' );
2018-02-22 15:37:01 +00:00
break ;
case 'country' :
2016-09-24 02:22:57 +00:00
$zone -> add_location ( $location_parts [ 1 ], 'country' );
2018-02-22 15:37:01 +00:00
break ;
case 'continent' :
2016-09-24 02:22:57 +00:00
$zone -> add_location ( $location_parts [ 1 ], 'continent' );
2018-02-22 15:37:01 +00:00
break ;
2016-09-24 02:22:57 +00:00
}
}
}
2016-10-10 17:41:07 +00:00
if ( isset ( $changes [ 'zone_postcodes' ] ) ) {
2016-09-24 02:22:57 +00:00
$zone -> clear_locations ( 'postcode' );
2016-10-10 17:41:07 +00:00
$postcodes = array_filter ( array_map ( 'strtoupper' , array_map ( 'wc_clean' , explode ( " \n " , $changes [ 'zone_postcodes' ] ) ) ) );
2016-09-24 02:22:57 +00:00
foreach ( $postcodes as $postcode ) {
$zone -> add_location ( $postcode , 'postcode' );
}
}
2015-12-15 17:48:03 +00:00
2016-10-10 17:41:07 +00:00
if ( isset ( $changes [ 'methods' ] ) ) {
foreach ( $changes [ 'methods' ] as $instance_id => $data ) {
$method_id = $wpdb -> get_var ( $wpdb -> prepare ( " SELECT method_id FROM { $wpdb -> prefix } woocommerce_shipping_zone_methods WHERE instance_id = %d " , $instance_id ) );
2016-05-10 18:43:47 +00:00
2016-10-10 17:41:07 +00:00
if ( isset ( $data [ 'deleted' ] ) ) {
$shipping_method = WC_Shipping_Zones :: get_shipping_method ( $instance_id );
$option_key = $shipping_method -> get_instance_option_key ();
if ( $wpdb -> delete ( " { $wpdb -> prefix } woocommerce_shipping_zone_methods " , array ( 'instance_id' => $instance_id ) ) ) {
delete_option ( $option_key );
do_action ( 'woocommerce_shipping_zone_method_deleted' , $instance_id , $method_id , $zone_id );
}
continue ;
2016-05-10 18:43:47 +00:00
}
2015-12-15 17:48:03 +00:00
2018-02-22 15:37:01 +00:00
$method_data = array_intersect_key (
2019-02-15 17:09:45 +00:00
$data ,
array (
2018-02-22 15:37:01 +00:00
'method_order' => 1 ,
'enabled' => 1 ,
)
);
2015-12-15 17:48:03 +00:00
2016-10-10 17:41:07 +00:00
if ( isset ( $method_data [ 'method_order' ] ) ) {
$wpdb -> update ( " { $wpdb -> prefix } woocommerce_shipping_zone_methods " , array ( 'method_order' => absint ( $method_data [ 'method_order' ] ) ), array ( 'instance_id' => absint ( $instance_id ) ) );
}
2016-03-15 17:23:06 +00:00
2016-10-10 17:41:07 +00:00
if ( isset ( $method_data [ 'enabled' ] ) ) {
$is_enabled = absint ( 'yes' === $method_data [ 'enabled' ] );
if ( $wpdb -> update ( " { $wpdb -> prefix } woocommerce_shipping_zone_methods " , array ( 'is_enabled' => $is_enabled ), array ( 'instance_id' => absint ( $instance_id ) ) ) ) {
do_action ( 'woocommerce_shipping_zone_method_status_toggled' , $instance_id , $method_id , $zone_id , $is_enabled );
}
2016-05-10 18:43:47 +00:00
}
2016-03-15 17:23:06 +00:00
}
2015-12-15 17:48:03 +00:00
}
2016-09-24 02:22:57 +00:00
$zone -> save ();
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'zone_id' => $zone -> get_id (),
'zone_name' => $zone -> get_zone_name (),
'methods' => $zone -> get_shipping_methods ( false , 'json' ),
)
);
2015-12-10 11:55:03 +00:00
}
2016-01-13 16:52:28 +00:00
2016-03-24 17:26:40 +00:00
/**
* Save method settings
*/
public static function shipping_zone_methods_save_settings () {
if ( ! isset ( $_POST [ 'wc_shipping_zones_nonce' ], $_POST [ 'instance_id' ], $_POST [ 'data' ] ) ) {
wp_send_json_error ( 'missing_fields' );
2018-02-26 17:27:25 +00:00
wp_die ();
2016-03-24 17:26:40 +00:00
}
2019-02-15 17:09:45 +00:00
if ( ! wp_verify_nonce ( wp_unslash ( $_POST [ 'wc_shipping_zones_nonce' ] ), 'wc_shipping_zones_nonce' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2016-03-24 17:26:40 +00:00
wp_send_json_error ( 'bad_nonce' );
2018-02-26 17:27:25 +00:00
wp_die ();
2016-03-24 17:26:40 +00:00
}
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
wp_send_json_error ( 'missing_capabilities' );
2018-02-26 17:27:25 +00:00
wp_die ();
2016-03-24 17:26:40 +00:00
}
$instance_id = absint ( $_POST [ 'instance_id' ] );
$zone = WC_Shipping_Zones :: get_zone_by ( 'instance_id' , $instance_id );
$shipping_method = WC_Shipping_Zones :: get_shipping_method ( $instance_id );
2019-02-15 17:09:45 +00:00
$shipping_method -> set_post_data ( wp_unslash ( $_POST [ 'data' ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2016-04-20 07:48:29 +00:00
$shipping_method -> process_admin_options ();
2016-03-24 17:26:40 +00:00
2018-04-10 11:25:09 +00:00
WC_Cache_Helper :: get_transient_version ( 'shipping' , true );
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'zone_id' => $zone -> get_id (),
'zone_name' => $zone -> get_zone_name (),
'methods' => $zone -> get_shipping_methods ( false , 'json' ),
'errors' => $shipping_method -> get_errors (),
)
);
2016-03-24 17:26:40 +00:00
}
2016-01-13 16:52:28 +00:00
/**
* Handle submissions from assets / js / wc - shipping - classes . js Backbone model .
*/
public static function shipping_classes_save_changes () {
if ( ! isset ( $_POST [ 'wc_shipping_classes_nonce' ], $_POST [ 'changes' ] ) ) {
wp_send_json_error ( 'missing_fields' );
2018-02-26 17:27:25 +00:00
wp_die ();
2016-01-13 16:52:28 +00:00
}
2019-02-15 17:09:45 +00:00
if ( ! wp_verify_nonce ( wp_unslash ( $_POST [ 'wc_shipping_classes_nonce' ] ), 'wc_shipping_classes_nonce' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2016-01-13 16:52:28 +00:00
wp_send_json_error ( 'bad_nonce' );
2018-02-26 17:27:25 +00:00
wp_die ();
2016-01-13 16:52:28 +00:00
}
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
wp_send_json_error ( 'missing_capabilities' );
2018-02-26 17:27:25 +00:00
wp_die ();
2016-01-13 16:52:28 +00:00
}
2019-02-15 17:09:45 +00:00
$changes = wp_unslash ( $_POST [ 'changes' ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2016-01-13 16:52:28 +00:00
foreach ( $changes as $term_id => $data ) {
$term_id = absint ( $term_id );
if ( isset ( $data [ 'deleted' ] ) ) {
if ( isset ( $data [ 'newRow' ] ) ) {
// So the user added and deleted a new row.
// That's fine, it's not in the database anyways. NEXT!
continue ;
}
wp_delete_term ( $term_id , 'product_shipping_class' );
continue ;
}
$update_args = array ();
if ( isset ( $data [ 'name' ] ) ) {
$update_args [ 'name' ] = wc_clean ( $data [ 'name' ] );
}
if ( isset ( $data [ 'slug' ] ) ) {
$update_args [ 'slug' ] = wc_clean ( $data [ 'slug' ] );
}
if ( isset ( $data [ 'description' ] ) ) {
$update_args [ 'description' ] = wc_clean ( $data [ 'description' ] );
}
if ( isset ( $data [ 'newRow' ] ) ) {
$update_args = array_filter ( $update_args );
if ( empty ( $update_args [ 'name' ] ) ) {
2016-05-12 11:18:35 +00:00
continue ;
2016-01-13 16:52:28 +00:00
}
2017-07-10 09:03:46 +00:00
$inserted_term = wp_insert_term ( $update_args [ 'name' ], 'product_shipping_class' , $update_args );
$term_id = is_wp_error ( $inserted_term ) ? 0 : $inserted_term [ 'term_id' ];
2016-01-13 16:52:28 +00:00
} else {
2016-05-19 11:38:28 +00:00
wp_update_term ( $term_id , 'product_shipping_class' , $update_args );
2016-01-13 16:52:28 +00:00
}
2016-05-19 11:38:28 +00:00
do_action ( 'woocommerce_shipping_classes_save_class' , $term_id , $data );
2016-01-13 16:52:28 +00:00
}
$wc_shipping = WC_Shipping :: instance ();
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'shipping_classes' => $wc_shipping -> get_shipping_classes (),
)
);
2016-01-13 16:52:28 +00:00
}
2018-04-12 15:59:42 +00:00
/**
* Toggle payment gateway on or off via AJAX .
*
* @ since 3.4 . 0
*/
public static function toggle_gateway_enabled () {
2019-02-15 17:09:45 +00:00
if ( current_user_can ( 'manage_woocommerce' ) && check_ajax_referer ( 'woocommerce-toggle-payment-gateway-enabled' , 'security' ) && isset ( $_POST [ 'gateway_id' ] ) ) {
2018-04-12 15:59:42 +00:00
// Load gateways.
$payment_gateways = WC () -> payment_gateways -> payment_gateways ();
// Get posted gateway.
$gateway_id = wc_clean ( wp_unslash ( $_POST [ 'gateway_id' ] ) );
foreach ( $payment_gateways as $gateway ) {
if ( ! in_array ( $gateway_id , array ( $gateway -> id , sanitize_title ( get_class ( $gateway ) ) ), true ) ) {
continue ;
}
$enabled = $gateway -> get_option ( 'enabled' , 'no' );
if ( ! wc_string_to_bool ( $enabled ) ) {
if ( $gateway -> needs_setup () ) {
wp_send_json_error ( 'needs_setup' );
wp_die ();
} else {
$gateway -> update_option ( 'enabled' , 'yes' );
}
} else {
// Disable the gateway.
$gateway -> update_option ( 'enabled' , 'no' );
}
wp_send_json_success ( ! wc_string_to_bool ( $enabled ) );
wp_die ();
}
}
wp_send_json_error ( 'invalid_gateway_id' );
wp_die ();
}
2013-11-14 12:13:34 +00:00
}
2014-05-28 13:52:50 +00:00
WC_AJAX :: init ();