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
*
2015-07-02 20:42:22 +00:00
* @ class WC_AJAX
* @ package WooCommerce / Classes
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-02-22 14:30:13 +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-02-26 18:51:46 +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' ), 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 () {
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 ) ) {
2018-02-22 14:30:13 +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
}
}
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 () {
send_origin_headers ();
@ header ( 'Content-Type: text/html; charset=' . get_option ( 'blog_charset' ) );
@ header ( 'X-Robots-Tag: noindex' );
send_nosniff_header ();
2017-11-08 15:07:00 +00:00
wc_nocache_headers ();
2015-11-30 12:10:31 +00:00
status_header ( 200 );
}
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 ;
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
}
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 () {
2018-02-22 15:37:01 +00:00
// woocommerce_EVENT => nopriv.
2013-11-14 12:13:34 +00:00
$ajax_events = array (
2018-04-12 15:59:42 +00:00
'get_refreshed_fragments' => true ,
'apply_coupon' => true ,
'remove_coupon' => true ,
'update_shipping_method' => true ,
'get_cart_totals' => true ,
'update_order_review' => true ,
'add_to_cart' => true ,
'remove_from_cart' => true ,
'checkout' => true ,
'get_variation' => true ,
'get_customer_location' => true ,
'feature_product' => false ,
'mark_order_status' => false ,
'get_order_details' => false ,
'add_attribute' => false ,
'add_new_attribute' => false ,
'remove_variation' => false ,
'remove_variations' => false ,
'save_attributes' => false ,
'add_variation' => false ,
'link_all_variations' => false ,
'revoke_access_to_download' => false ,
'grant_access_to_download' => false ,
'get_customer_details' => false ,
'add_order_item' => false ,
'add_order_fee' => false ,
'add_order_shipping' => false ,
'add_order_tax' => false ,
'add_coupon_discount' => false ,
'remove_order_coupon' => false ,
'remove_order_item' => false ,
'remove_order_tax' => false ,
'reduce_order_item_stock' => false ,
'increase_order_item_stock' => false ,
'add_order_item_meta' => false ,
'remove_order_item_meta' => false ,
'calc_line_taxes' => false ,
'save_order_items' => false ,
'load_order_items' => false ,
'add_order_note' => false ,
'delete_order_note' => false ,
'json_search_products' => false ,
'json_search_products_and_variations' => false ,
2014-07-10 12:33:05 +00:00
'json_search_downloadable_products_and_variations' => false ,
2018-04-12 15:59:42 +00:00
'json_search_customers' => false ,
'json_search_categories' => false ,
'term_ordering' => false ,
'product_ordering' => false ,
'refund_line_items' => false ,
'delete_refund' => false ,
'rated' => false ,
'update_api_key' => false ,
'load_variations' => false ,
'save_variations' => false ,
'bulk_edit_variations' => false ,
'tax_rates_save_changes' => false ,
'shipping_zones_save_changes' => false ,
'shipping_zone_add_method' => false ,
'shipping_zone_methods_save_changes' => false ,
'shipping_zone_methods_save_settings' => false ,
'shipping_classes_save_changes' => false ,
'toggle_gateway_enabled' => false ,
2013-11-14 12:13:34 +00:00
);
2014-01-26 09:19:17 +00:00
2013-11-14 12:13:34 +00:00
foreach ( $ajax_events as $ajax_event => $nopriv ) {
2014-05-28 13:52:50 +00:00
add_action ( 'wp_ajax_woocommerce_' . $ajax_event , array ( __CLASS__ , $ajax_event ) );
2013-11-14 12:13:34 +00:00
2014-05-12 13:04:36 +00:00
if ( $nopriv ) {
2014-05-28 13:52:50 +00:00
add_action ( 'wp_ajax_nopriv_woocommerce_' . $ajax_event , array ( __CLASS__ , $ajax_event ) );
2015-03-20 12:28:26 +00:00
2016-11-24 11:50:58 +00:00
// WC AJAX can be used for frontend ajax requests.
2015-03-20 12:28:26 +00:00
add_action ( 'wc_ajax_' . $ajax_event , array ( __CLASS__ , $ajax_event ) );
2014-05-12 13:04:36 +00:00
}
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 (
'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
)
),
2016-08-27 01:46:45 +00:00
'cart_hash' => apply_filters ( 'woocommerce_add_to_cart_hash' , WC () -> cart -> get_cart_for_session () ? md5 ( json_encode ( WC () -> cart -> get_cart_for_session () ) ) : '' , WC () -> cart -> get_cart_for_session () ),
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' ] ) ) {
2018-02-22 15:37:01 +00:00
WC () -> cart -> add_discount ( sanitize_text_field ( wp_unslash ( $_POST [ 'coupon_code' ] ) ) );
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' );
2017-03-22 10:53:18 +00:00
$coupon = isset ( $_POST [ 'coupon' ] ) ? wc_clean ( $_POST [ 'coupon' ] ) : false ;
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' );
2014-04-25 11:30:39 +00:00
if ( isset ( $_POST [ 'shipping_method' ] ) && is_array ( $_POST [ 'shipping_method' ] ) ) {
foreach ( $_POST [ 'shipping_method' ] as $i => $value ) {
2013-11-25 13:34:21 +00:00
$chosen_shipping_methods [ $i ] = wc_clean ( $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 (
'woocommerce_update_order_review_fragments' , array (
'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-05-22 10:19:09 +00:00
if ( WC () -> cart -> is_empty () && ! is_customize_preview () ) {
2016-11-24 14:20:58 +00:00
self :: update_order_review_expired ();
2013-11-14 12:13:34 +00:00
}
do_action ( 'woocommerce_checkout_update_order_review' , $_POST [ 'post_data' ] );
$chosen_shipping_methods = WC () -> session -> get ( 'chosen_shipping_methods' );
2014-05-12 13:04:36 +00:00
if ( isset ( $_POST [ 'shipping_method' ] ) && is_array ( $_POST [ 'shipping_method' ] ) ) {
foreach ( $_POST [ 'shipping_method' ] as $i => $value ) {
2013-11-25 13:34:21 +00:00
$chosen_shipping_methods [ $i ] = wc_clean ( $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 );
WC () -> session -> set ( 'chosen_payment_method' , empty ( $_POST [ 'payment_method' ] ) ? '' : $_POST [ 'payment_method' ] );
2018-02-22 15:37:01 +00:00
WC () -> customer -> set_props (
array (
'billing_country' => isset ( $_POST [ 'country' ] ) ? wp_unslash ( $_POST [ 'country' ] ) : null ,
'billing_state' => isset ( $_POST [ 'state' ] ) ? wp_unslash ( $_POST [ 'state' ] ) : null ,
'billing_postcode' => isset ( $_POST [ 'postcode' ] ) ? wp_unslash ( $_POST [ 'postcode' ] ) : null ,
'billing_city' => isset ( $_POST [ 'city' ] ) ? wp_unslash ( $_POST [ 'city' ] ) : null ,
'billing_address_1' => isset ( $_POST [ 'address' ] ) ? wp_unslash ( $_POST [ 'address' ] ) : null ,
'billing_address_2' => isset ( $_POST [ 'address_2' ] ) ? wp_unslash ( $_POST [ 'address_2' ] ) : null ,
)
);
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 (
'shipping_country' => isset ( $_POST [ 'country' ] ) ? wp_unslash ( $_POST [ 'country' ] ) : null ,
'shipping_state' => isset ( $_POST [ 'state' ] ) ? wp_unslash ( $_POST [ 'state' ] ) : null ,
'shipping_postcode' => isset ( $_POST [ 'postcode' ] ) ? wp_unslash ( $_POST [ 'postcode' ] ) : null ,
'shipping_city' => isset ( $_POST [ 'city' ] ) ? wp_unslash ( $_POST [ 'city' ] ) : null ,
'shipping_address_1' => isset ( $_POST [ 'address' ] ) ? wp_unslash ( $_POST [ 'address' ] ) : null ,
'shipping_address_2' => isset ( $_POST [ 'address_2' ] ) ? wp_unslash ( $_POST [ 'address_2' ] ) : null ,
)
);
2014-02-14 11:19:32 +00:00
} else {
2018-02-22 15:37:01 +00:00
WC () -> customer -> set_props (
array (
'shipping_country' => isset ( $_POST [ 's_country' ] ) ? wp_unslash ( $_POST [ 's_country' ] ) : null ,
'shipping_state' => isset ( $_POST [ 's_state' ] ) ? wp_unslash ( $_POST [ 's_state' ] ) : null ,
'shipping_postcode' => isset ( $_POST [ 's_postcode' ] ) ? wp_unslash ( $_POST [ 's_postcode' ] ) : null ,
'shipping_city' => isset ( $_POST [ 's_city' ] ) ? wp_unslash ( $_POST [ 's_city' ] ) : null ,
'shipping_address_1' => isset ( $_POST [ 's_address' ] ) ? wp_unslash ( $_POST [ 's_address' ] ) : null ,
'shipping_address_2' => isset ( $_POST [ 's_address_2' ] ) ? wp_unslash ( $_POST [ 's_address_2' ] ) : null ,
)
);
2017-09-08 13:54:15 +00:00
}
if ( wc_string_to_bool ( $_POST [ 'has_full_address' ] ) ) {
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 ();
2013-11-14 12:13:34 +00:00
WC () -> cart -> calculate_totals ();
2014-12-04 08:40:49 +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 ();
2015-01-27 22:41:33 +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 ();
2014-12-04 08:40:49 +00:00
// Get messages if reload checkout is not true
if ( ! isset ( WC () -> session -> 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 ,
'reload' => isset ( WC () -> session -> reload_checkout ) ? 'true' : 'false' ,
'fragments' => apply_filters (
'woocommerce_update_order_review_fragments' , array (
'.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 ();
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 );
2014-06-25 10:25:28 +00:00
$quantity = empty ( $_POST [ 'quantity' ] ) ? 1 : wc_stock_amount ( $_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
}
// Return fragments
2014-05-28 13:52:50 +00:00
self :: get_refreshed_fragments ();
2013-11-14 12:13:34 +00:00
} else {
// If there was an error adding to the cart, redirect to the product page to show any errors
$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
}
}
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 ();
$cart_item_key = wc_clean ( $_POST [ 'cart_item_key' ] );
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 ();
2016-11-24 15:31:05 +00:00
if ( empty ( $_POST [ 'product_id' ] ) || ! ( $variable_product = wc_get_product ( absint ( $_POST [ 'product_id' ] ) ) ) ) {
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 );
}
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 () {
2014-11-27 15:40:39 +00:00
if ( current_user_can ( 'edit_products' ) && check_admin_referer ( 'woocommerce-feature-product' ) ) {
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 () {
2014-11-27 15:37:42 +00:00
if ( current_user_can ( 'edit_shop_orders' ) && check_admin_referer ( 'woocommerce-mark-order-status' ) ) {
2016-11-24 11:50:58 +00:00
$status = sanitize_text_field ( $_GET [ 'status' ] );
$order = wc_get_order ( absint ( $_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.
wc () -> payment_gateways ();
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' );
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
wp_die ( - 1 );
}
2017-11-20 22:43:37 +00:00
$order = wc_get_order ( absint ( $_GET [ 'order_id' ] ) ); // WPCS: sanitization ok.
2017-09-04 16:42:31 +00:00
2017-11-20 22:43:37 +00:00
if ( $order ) {
2018-02-22 15:37:01 +00:00
include_once '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' );
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
}
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
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_id ( wc_attribute_taxonomy_id_by_name ( sanitize_text_field ( $_POST [ 'taxonomy' ] ) ) );
$attribute -> set_name ( sanitize_text_field ( $_POST [ 'taxonomy' ] ) );
$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
}
2018-02-22 15:37:01 +00:00
include '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' );
2016-11-24 11:50:58 +00:00
if ( current_user_can ( 'manage_product_terms' ) ) {
$taxonomy = esc_attr ( $_POST [ 'taxonomy' ] );
$term = wc_clean ( $_POST [ 'term' ] );
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
2016-11-24 11:50:58 +00:00
if ( current_user_can ( 'edit_products' ) ) {
$variation_ids = ( array ) $_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' );
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
}
2013-11-14 12:13:34 +00:00
parse_str ( $_POST [ 'data' ], $data );
2017-01-05 16:54:47 +00:00
$attributes = WC_Meta_Box_Product_Data :: prepare_attributes ( $data );
$product_id = absint ( $_POST [ 'post_id' ] );
$product_type = ! empty ( $_POST [ 'product_type' ] ) ? wc_clean ( $_POST [ 'product_type' ] ) : 'simple' ;
$classname = WC_Product_Factory :: get_product_classname ( $product_id , $product_type );
$product = new $classname ( $product_id );
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 -> set_attributes ( $attributes );
$product -> save ();
2017-01-29 20:43:25 +00:00
wp_die ();
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' );
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
}
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' ] );
$post = get_post ( $product_id );
$loop = intval ( $_POST [ 'loop' ] );
$product_object = wc_get_product ( $product_id );
$variation_object = new WC_Product_Variation ();
$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 );
$variation_data = array_merge ( array_map ( 'maybe_unserialize' , get_post_custom ( $variation_id ) ), wc_get_product_variation_attributes ( $variation_id ) ); // kept for BW compatibility.
include '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
}
2016-11-24 14:20:58 +00:00
wc_maybe_define_constant ( 'WC_MAX_LINKED_VARIATIONS' , 49 );
2016-06-06 15:55:27 +00:00
wc_set_time_limit ( 0 );
2013-11-14 12:13:34 +00:00
$post_id = intval ( $_POST [ 'post_id' ] );
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 );
2017-01-05 16:17:46 +00:00
$attributes = wc_list_pluck ( array_filter ( $product -> get_attributes (), 'wc_attributes_array_filter_variation' ), 'get_slugs' );
2013-11-14 12:13:34 +00:00
2017-01-05 16:17:46 +00:00
if ( ! empty ( $attributes ) ) {
// Get existing variations so we don't create duplicates.
$existing_variations = array_map ( 'wc_get_product' , $product -> get_children () );
$existing_attributes = array ();
2013-11-14 12:13:34 +00:00
2017-01-05 16:17:46 +00:00
foreach ( $existing_variations as $existing_variation ) {
$existing_attributes [] = $existing_variation -> get_attributes ();
}
2013-11-14 12:13:34 +00:00
2017-01-05 16:17:46 +00:00
$added = 0 ;
2017-07-17 10:02:43 +00:00
$possible_attributes = array_reverse ( wc_array_cartesian ( $attributes ) );
2013-11-14 12:13:34 +00:00
2017-01-05 16:17:46 +00:00
foreach ( $possible_attributes as $possible_attribute ) {
if ( in_array ( $possible_attribute , $existing_attributes ) ) {
continue ;
}
$variation = new WC_Product_Variation ();
$variation -> set_parent_id ( $post_id );
$variation -> set_attributes ( $possible_attribute );
2013-11-14 12:13:34 +00:00
2017-01-05 16:17:46 +00:00
do_action ( 'product_variation_linked' , $variation -> save () );
2013-11-14 12:13:34 +00:00
2017-01-05 16:17:46 +00:00
if ( ( $added ++ ) > WC_MAX_LINKED_VARIATIONS ) {
break ;
2016-11-24 14:20:58 +00:00
}
2014-05-12 13:04:36 +00:00
}
2016-12-08 14:28:51 +00:00
2017-01-05 16:17:46 +00:00
echo $added ;
2013-11-14 12:13:34 +00:00
}
2017-01-05 16:17:46 +00:00
$data_store = $product -> get_data_store ();
$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' );
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
}
2016-07-14 13:54:28 +00:00
$download_id = $_POST [ 'download_id' ];
$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' );
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
}
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' ] );
$product_ids = $_POST [ 'product_ids' ];
$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
2013-11-26 13:54:34 +00:00
if ( ! is_array ( $product_ids ) ) {
$product_ids = array ( $product_ids );
}
2013-11-14 12:13:34 +00:00
2013-11-26 13:54:34 +00:00
foreach ( $product_ids as $product_id ) {
2014-08-19 10:09:29 +00:00
$product = wc_get_product ( $product_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
$files = $product -> get_downloads ();
2013-11-14 12:13:34 +00:00
2016-08-05 14:57:40 +00:00
if ( ! $order -> get_billing_email () ) {
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-06-06 18:39:23 +00:00
if ( ! empty ( $files ) ) {
2013-11-26 13:54:34 +00:00
foreach ( $files as $download_id => $file ) {
if ( $inserted_id = wc_downloadable_file_permission ( $download_id , $product_id , $order ) ) {
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 {
$file_count = sprintf ( __ ( 'File %d' , 'woocommerce' ), $file_counter );
}
2018-02-22 15:37:01 +00:00
include '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' );
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
}
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
}
/**
2015-11-03 13:31:20 +00:00
* Add order item via ajax .
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
}
2016-08-24 15:02:19 +00:00
try {
2017-02-23 10:19:32 +00:00
$order_id = absint ( $_POST [ 'order_id' ] );
$order = wc_get_order ( $order_id );
$items_to_add = wp_parse_id_list ( is_array ( $_POST [ 'item_to_add' ] ) ? $_POST [ 'item_to_add' ] : array ( $_POST [ 'item_to_add' ] ) );
2017-10-27 11:38:10 +00:00
$items = ( ! empty ( $_POST [ 'items' ] ) ) ? $_POST [ 'items' ] : '' ;
2018-05-02 11:49:24 +00:00
$added_items = array ();
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 we passed through items it means we need to save first before adding a new one.
if ( ! empty ( $items ) ) {
$save_items = array ();
parse_str ( $items , $save_items );
// Save order items.
wc_save_order_items ( $order -> get_id (), $save_items );
}
2017-02-23 10:19:32 +00:00
foreach ( $items_to_add as $item_to_add ) {
2018-05-02 11:49:24 +00:00
2017-02-23 10:19:32 +00:00
if ( ! in_array ( get_post_type ( $item_to_add ), array ( 'product' , 'product_variation' ) ) ) {
continue ;
}
2018-05-02 11:49:24 +00:00
2018-02-22 15:37:01 +00:00
$item_id = $order -> add_product ( wc_get_product ( $item_to_add ) );
$item = apply_filters ( 'woocommerce_ajax_order_item' , $order -> get_item ( $item_id ), $item_id );
2018-05-02 11:49:24 +00:00
$added_items [ $item_id ] = $item ;
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
2018-05-02 11:49:24 +00:00
$last_item = ! empty ( $added_items ) ? end ( $added_items ) : null ;
wc_do_deprecated_action ( 'woocommerce_ajax_added_order_items' , array ( is_a ( $last_item , 'WC_Order_Item' ) ? $last_item -> get_id () : null , $last_item , $order ), '3.4' , 'woocommerce_ajax_order_items_added action instead.' );
do_action ( 'woocommerce_ajax_order_items_added' , $added_items , $order );
2017-08-22 12:19:20 +00:00
$data = get_post_meta ( $order_id );
ob_start ();
2018-02-22 15:37:01 +00:00
include 'admin/meta-boxes/views/html-order-items.php' ;
wp_send_json_success (
array (
'html' => ob_get_clean (),
)
);
2016-08-25 13:22:27 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2013-11-14 12:13:34 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Add order fee via ajax .
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
}
2016-08-24 15:02:19 +00:00
try {
2017-11-02 17:31:03 +00:00
$order_id = absint ( $_POST [ 'order_id' ] );
$amount = wc_clean ( $_POST [ 'amount' ] );
$order = wc_get_order ( $order_id );
$calculate_tax_args = array (
'country' => strtoupper ( wc_clean ( $_POST [ 'country' ] ) ),
'state' => strtoupper ( wc_clean ( $_POST [ 'state' ] ) ),
'postcode' => strtoupper ( wc_clean ( $_POST [ 'postcode' ] ) ),
'city' => strtoupper ( wc_clean ( $_POST [ 'city' ] ) ),
);
2017-08-23 10:22:18 +00:00
if ( ! $order ) {
throw new exception ( __ ( 'Invalid order' , 'woocommerce' ) );
}
if ( strstr ( $amount , '%' ) ) {
$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 );
$fee -> set_name ( sprintf ( __ ( '%s fee' , 'woocommerce' ), $formatted_amount ) );
$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 ();
2018-02-22 15:37:01 +00:00
include 'admin/meta-boxes/views/html-order-items.php' ;
2016-08-25 13:22:27 +00:00
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'html' => ob_get_clean (),
)
);
2016-08-25 13:22:27 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
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 .
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
}
2016-08-24 15:02:19 +00:00
try {
$order_id = absint ( $_POST [ 'order_id' ] );
$order = wc_get_order ( $order_id );
$order_taxes = $order -> get_taxes ();
$shipping_methods = WC () -> shipping () ? WC () -> shipping -> load_shipping_methods () : array ();
2014-07-24 20:55:25 +00:00
2016-08-24 15:02:19 +00:00
// Add new shipping
$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 ();
2018-02-22 15:37:01 +00:00
include 'admin/meta-boxes/views/html-order-shipping.php' ;
2014-07-16 18:41:18 +00:00
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'html' => ob_get_clean (),
)
);
2016-08-25 13:22:27 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
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 .
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
}
2016-08-24 15:02:19 +00:00
try {
$order_id = absint ( $_POST [ 'order_id' ] );
$rate_id = absint ( $_POST [ 'rate_id' ] );
$order = wc_get_order ( $order_id );
$data = get_post_meta ( $order_id );
// Add new tax
$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 ();
2018-02-22 15:37:01 +00:00
include 'admin/meta-boxes/views/html-order-items.php' ;
2014-07-21 01:36:12 +00:00
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'html' => ob_get_clean (),
)
);
2016-08-25 13:22:27 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2014-07-21 01:36:12 +00:00
}
2017-08-09 13:54:30 +00:00
/**
* Add order discount via ajax .
*/
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 );
}
try {
$order_id = absint ( $_POST [ 'order_id' ] );
$order = wc_get_order ( $order_id );
2017-09-27 11:50:20 +00:00
$result = $order -> apply_coupon ( wc_clean ( $_POST [ 'coupon' ] ) );
2017-08-09 13:54:30 +00:00
2017-09-27 11:50:20 +00:00
if ( is_wp_error ( $result ) ) {
throw new Exception ( $result -> get_error_message () );
}
2017-08-09 13:54:30 +00:00
ob_start ();
2018-02-22 15:37:01 +00:00
include 'admin/meta-boxes/views/html-order-items.php' ;
2017-08-09 13:54:30 +00:00
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'html' => ob_get_clean (),
)
);
2017-08-09 13:54:30 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
}
2017-08-09 21:55:35 +00:00
/**
* Remove coupon from an order via ajax .
*/
public static function remove_order_coupon () {
check_ajax_referer ( 'order-item' , 'security' );
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
wp_die ( - 1 );
}
try {
$order_id = absint ( $_POST [ 'order_id' ] );
$order = wc_get_order ( $order_id );
$order -> remove_coupon ( wc_clean ( $_POST [ 'coupon' ] ) );
ob_start ();
2018-02-22 15:37:01 +00:00
include 'admin/meta-boxes/views/html-order-items.php' ;
2017-08-09 21:55:35 +00:00
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'html' => ob_get_clean (),
)
);
2017-08-09 21:55:35 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
}
2013-11-14 12:13:34 +00:00
/**
2015-11-03 13:31:20 +00:00
* Remove an order item .
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' );
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
}
2017-08-10 15:32:24 +00:00
try {
2017-11-02 17:31:03 +00:00
$order_id = absint ( $_POST [ 'order_id' ] );
$order_item_ids = $_POST [ 'order_item_ids' ];
2018-02-22 15:37:01 +00:00
$items = ( ! empty ( $_POST [ 'items' ] ) ) ? $_POST [ 'items' ] : '' ;
2017-11-02 17:31:03 +00:00
$calculate_tax_args = array (
'country' => strtoupper ( wc_clean ( $_POST [ 'country' ] ) ),
'state' => strtoupper ( wc_clean ( $_POST [ 'state' ] ) ),
'postcode' => strtoupper ( wc_clean ( $_POST [ 'postcode' ] ) ),
'city' => strtoupper ( wc_clean ( $_POST [ 'city' ] ) ),
);
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 );
// Save order items
wc_save_order_items ( $order_id , $save_items );
}
2017-08-10 15:32:24 +00:00
if ( sizeof ( $order_item_ids ) > 0 ) {
foreach ( $order_item_ids as $id ) {
wc_delete_order_item ( absint ( $id ) );
}
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
ob_start ();
2018-02-22 15:37:01 +00:00
include 'admin/meta-boxes/views/html-order-items.php' ;
2017-08-10 15:32:24 +00:00
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'html' => ob_get_clean (),
)
);
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
}
}
2014-07-21 01:57:23 +00:00
/**
2015-11-03 13:31:20 +00:00
* Remove an order tax .
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' );
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
}
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
2017-08-10 15:32:24 +00:00
wc_delete_order_item ( $rate_id );
2014-07-21 01:57:23 +00:00
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 ();
2018-02-22 15:37:01 +00:00
include 'admin/meta-boxes/views/html-order-items.php' ;
2017-08-10 15:32:24 +00:00
2018-02-22 15:37:01 +00:00
wp_send_json_success (
array (
'html' => ob_get_clean (),
)
);
2017-08-10 15:32:24 +00:00
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'error' => $e -> getMessage () ) );
}
2014-07-21 01:57:23 +00:00
}
2016-03-22 17:13:39 +00:00
/**
* Reduce order item stock .
*/
public static function reduce_order_item_stock () {
check_ajax_referer ( 'order-item' , 'security' );
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2016-03-22 17:13:39 +00:00
}
$order_id = absint ( $_POST [ 'order_id' ] );
$order_item_ids = isset ( $_POST [ 'order_item_ids' ] ) ? $_POST [ 'order_item_ids' ] : array ();
$order_item_qty = isset ( $_POST [ 'order_item_qty' ] ) ? $_POST [ 'order_item_qty' ] : array ();
$order = wc_get_order ( $order_id );
$order_items = $order -> get_items ();
$return = array ();
if ( $order && ! empty ( $order_items ) && sizeof ( $order_item_ids ) > 0 ) {
foreach ( $order_items as $item_id => $order_item ) {
// Only reduce checked items
if ( ! in_array ( $item_id , $order_item_ids ) ) {
continue ;
}
2016-08-22 15:51:24 +00:00
$_product = $order_item -> get_product ();
2017-03-17 16:26:26 +00:00
if ( $_product && $_product -> exists () && $_product -> managing_stock () && isset ( $order_item_qty [ $item_id ] ) && $order_item_qty [ $item_id ] > 0 ) {
2016-03-22 17:13:39 +00:00
$stock_change = apply_filters ( 'woocommerce_reduce_order_stock_quantity' , $order_item_qty [ $item_id ], $item_id );
2017-02-23 15:54:04 +00:00
$new_stock = wc_update_product_stock ( $_product , $stock_change , 'decrease' );
2017-12-10 04:22:41 +00:00
$item_name = $_product -> get_formatted_name ();
$return [] = array (
'note' => sprintf ( wp_kses_post ( __ ( '%1$s stock reduced from %2$s to %3$s.' , 'woocommerce' ) ), $item_name , $new_stock + $stock_change , $new_stock ),
'success' => true ,
);
2016-03-22 17:13:39 +00:00
}
}
do_action ( 'woocommerce_reduce_order_stock' , $order );
2018-02-19 14:56:30 +00:00
2016-03-22 17:13:39 +00:00
if ( empty ( $return ) ) {
2017-12-10 04:22:41 +00:00
$return [] = array (
'note' => wp_kses_post ( __ ( 'No products had their stock reduced - they may not have stock management enabled.' , 'woocommerce' ) ),
'success' => false ,
);
2016-03-22 17:13:39 +00:00
}
2018-02-19 14:56:30 +00:00
wp_send_json_success ( $return );
2016-03-22 17:13:39 +00:00
}
2018-02-19 14:56:30 +00:00
wp_send_json_error ();
2016-03-22 17:13:39 +00:00
}
/**
* Increase order item stock .
*/
public static function increase_order_item_stock () {
check_ajax_referer ( 'order-item' , 'security' );
if ( ! current_user_can ( 'edit_shop_orders' ) ) {
2017-01-29 20:43:25 +00:00
wp_die ( - 1 );
2016-03-22 17:13:39 +00:00
}
$order_id = absint ( $_POST [ 'order_id' ] );
$order_item_ids = isset ( $_POST [ 'order_item_ids' ] ) ? $_POST [ 'order_item_ids' ] : array ();
$order_item_qty = isset ( $_POST [ 'order_item_qty' ] ) ? $_POST [ 'order_item_qty' ] : array ();
$order = wc_get_order ( $order_id );
$order_items = $order -> get_items ();
$return = array ();
if ( $order && ! empty ( $order_items ) && sizeof ( $order_item_ids ) > 0 ) {
foreach ( $order_items as $item_id => $order_item ) {
// Only reduce checked items
if ( ! in_array ( $item_id , $order_item_ids ) ) {
continue ;
}
2016-08-22 15:51:24 +00:00
$_product = $order_item -> get_product ();
2017-03-17 16:26:26 +00:00
if ( $_product && $_product -> exists () && $_product -> managing_stock () && isset ( $order_item_qty [ $item_id ] ) && $order_item_qty [ $item_id ] > 0 ) {
2016-03-22 17:13:39 +00:00
$old_stock = $_product -> get_stock_quantity ();
$stock_change = apply_filters ( 'woocommerce_restore_order_stock_quantity' , $order_item_qty [ $item_id ], $item_id );
2017-02-23 15:54:04 +00:00
$new_quantity = wc_update_product_stock ( $_product , $stock_change , 'increase' );
2017-12-10 04:22:41 +00:00
$item_name = $_product -> get_formatted_name ();
$return [] = array (
'note' => sprintf ( wp_kses_post ( __ ( '%1$s stock increased from %2$s to %3$s.' , 'woocommerce' ) ), $item_name , $old_stock , $new_quantity ),
'success' => true ,
);
2016-03-22 17:13:39 +00:00
}
}
do_action ( 'woocommerce_restore_order_stock' , $order );
if ( empty ( $return ) ) {
2017-12-10 04:22:41 +00:00
$return [] = array (
'note' => wp_kses_post ( __ ( 'No products had their stock increased - they may not have stock management enabled.' , 'woocommerce' ) ),
'success' => false ,
);
2016-03-22 17:13:39 +00:00
}
2018-02-19 14:56:30 +00:00
wp_send_json_success ( $return );
2016-03-22 17:13:39 +00:00
}
2018-02-19 14:56:30 +00:00
wp_send_json_error ();
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' );
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
}
2016-08-22 15:48:19 +00:00
$order_id = absint ( $_POST [ 'order_id' ] );
$calculate_tax_args = array (
'country' => strtoupper ( wc_clean ( $_POST [ 'country' ] ) ),
'state' => strtoupper ( wc_clean ( $_POST [ 'state' ] ) ),
'postcode' => strtoupper ( wc_clean ( $_POST [ 'postcode' ] ) ),
'city' => strtoupper ( wc_clean ( $_POST [ 'city' ] ) ),
);
2015-10-05 14:31:58 +00:00
2014-07-24 21:09:13 +00:00
// Parse the jQuery serialized items
2016-08-22 15:48:19 +00:00
$items = array ();
2014-07-24 21:09:13 +00:00
parse_str ( $_POST [ 'items' ], $items );
2016-08-22 15:48:19 +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
2017-07-17 10:10:52 +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 );
2018-02-22 15:37:01 +00:00
include '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' );
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
}
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' ] );
// Parse the jQuery serialized items
$items = array ();
parse_str ( $_POST [ 'items' ], $items );
// Save order items
wc_save_order_items ( $order_id , $items );
// Return HTML items
2014-11-26 22:22:38 +00:00
$order = wc_get_order ( $order_id );
2018-02-22 15:37:01 +00:00
include 'admin/meta-boxes/views/html-order-items.php' ;
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' );
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
}
2014-07-17 20:17:54 +00:00
// Return HTML items
$order_id = absint ( $_POST [ 'order_id' ] );
2014-11-26 22:22:38 +00:00
$order = wc_get_order ( $order_id );
2018-02-22 15:37:01 +00:00
include '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' );
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
}
2015-03-03 16:36:47 +00:00
$post_id = absint ( $_POST [ 'post_id' ] );
2018-02-22 15:37:01 +00:00
$note = wp_kses_post ( trim ( wp_unslash ( $_POST [ 'note' ] ) ) );
2014-05-12 13:04:36 +00:00
$note_type = $_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 " >
< ? php echo wpautop ( wptexturize ( wp_kses_post ( $note -> content ) ) ); ?>
</ div >
< p class = " meta " >
< abbr class = " exact-date " title = " <?php echo $note->date_created ->date( 'y-m-d h:i:s' ); ?> " >
< ? php printf ( __ ( 'added on %1$s at %2$s' , 'woocommerce' ), $note -> date_created -> date_i18n ( wc_date_format () ), $note -> date_created -> date_i18n ( wc_time_format () ) ); ?>
</ abbr >
< ? php
if ( 'system' !== $note -> added_by ) :
/* translators: %s: note author */
printf ( ' ' . __ ( 'by %s' , 'woocommerce' ), $note -> added_by );
endif ;
?>
< a href = " # " class = " delete_note " role = " button " >< ? php _e ( 'Delete note' , 'woocommerce' ); ?> </a>
</ 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' );
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
}
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
*
2016-06-07 13:10:23 +00:00
* @ param string $term ( default : '' )
2018-02-22 15:37:01 +00:00
* @ 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' );
2018-02-22 15:37:01 +00:00
$term = wc_clean ( empty ( $term ) ? wp_unslash ( $_GET [ 'term' ] ) : $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
2016-11-24 11:50:58 +00:00
$data_store = WC_Data_Store :: load ( 'product' );
$ids = $data_store -> search_products ( $term , '' , ( bool ) $include_variations );
2013-11-14 12:13:34 +00:00
2015-10-02 08:00:26 +00:00
if ( ! empty ( $_GET [ 'exclude' ] ) ) {
2016-11-24 11:50:58 +00:00
$ids = array_diff ( $ids , ( array ) $_GET [ 'exclude' ] );
2013-11-14 12:13:34 +00:00
}
2015-12-12 12:28:45 +00:00
if ( ! empty ( $_GET [ 'include' ] ) ) {
2016-12-27 08:36:44 +00:00
$ids = array_intersect ( $ids , ( array ) $_GET [ 'include' ] );
2015-12-12 12:28:45 +00:00
}
if ( ! empty ( $_GET [ 'limit' ] ) ) {
2016-11-24 11:50:58 +00:00
$ids = array_slice ( $ids , 0 , absint ( $_GET [ 'limit' ] ) );
2015-12-12 12:28:45 +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-12-12 14:37:32 +00:00
2016-11-24 11:50:58 +00:00
foreach ( $product_objects as $product_object ) {
$products [ $product_object -> get_id () ] = rawurldecode ( $product_object -> get_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' );
2018-02-22 15:37:01 +00:00
$term = ( string ) wc_clean ( wp_unslash ( $_GET [ 'term' ] ) );
2016-11-24 11:50:58 +00:00
$data_store = WC_Data_Store :: load ( 'product' );
$ids = $data_store -> search_products ( $term , 'downloadable' , true );
2015-07-20 16:41:14 +00:00
if ( ! empty ( $_GET [ 'exclude' ] ) ) {
2016-11-24 11:50:58 +00:00
$ids = array_diff ( $ids , ( array ) $_GET [ 'exclude' ] );
2015-07-20 16:41:14 +00:00
}
2013-11-26 13:54:34 +00:00
2016-11-24 11:50:58 +00:00
if ( ! empty ( $_GET [ 'include' ] ) ) {
2017-04-19 10:20:05 +00:00
$ids = array_intersect ( $ids , ( array ) $_GET [ 'include' ] );
2016-11-24 11:50:58 +00:00
}
2014-05-12 13:04:36 +00:00
2016-11-24 11:50:58 +00:00
if ( ! empty ( $_GET [ 'limit' ] ) ) {
$ids = array_slice ( $ids , 0 , absint ( $_GET [ '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 ) {
$products [ $product_object -> get_id () ] = rawurldecode ( $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
}
2018-02-22 15:37:01 +00:00
$term = wc_clean ( wp_unslash ( $_GET [ 'term' ] ) );
2016-02-16 13:55:36 +00:00
$exclude = array ();
2017-05-16 09:16:04 +00:00
$limit = '' ;
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' ] ) ) {
$ids = array_diff ( $ids , ( array ) $_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 (
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 );
}
2018-02-22 15:37:01 +00:00
if ( ! $search_text = wc_clean ( wp_unslash ( $_GET [ 'term' ] ) ) ) {
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 ,
);
if ( $terms = get_terms ( $args ) ) {
foreach ( $terms as $term ) {
$term -> formatted_name = '' ;
if ( $term -> parent ) {
$ancestors = array_reverse ( get_ancestors ( $term -> term_id , 'product_cat' ) );
foreach ( $ancestors as $ancestor ) {
if ( $ancestor_term = get_term ( $ancestor , 'product_cat' ) ) {
$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 ) );
}
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 () {
2015-05-29 13:55:26 +00:00
// check permissions again and make sure we have what we need
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 ;
$taxonomy = isset ( $_POST [ 'thetaxonomy' ] ) ? esc_attr ( $_POST [ 'thetaxonomy' ] ) : null ;
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
2014-05-12 13:04:36 +00:00
if ( $term && sizeof ( $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
}
}
/**
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 ;
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
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 );
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
}
2014-07-25 10:29:24 +00:00
$order_id = absint ( $_POST [ 'order_id' ] );
2018-02-22 15:37:01 +00:00
$refund_amount = wc_format_decimal ( sanitize_text_field ( wp_unslash ( $_POST [ 'refund_amount' ] ) ), wc_get_price_decimals () );
$refunded_amount = wc_format_decimal ( sanitize_text_field ( wp_unslash ( $_POST [ 'refunded_amount' ] ) ), wc_get_price_decimals () );
2014-07-25 10:29:24 +00:00
$refund_reason = sanitize_text_field ( $_POST [ 'refund_reason' ] );
2018-02-22 15:37:01 +00:00
$line_item_qtys = json_decode ( sanitize_text_field ( wp_unslash ( $_POST [ 'line_item_qtys' ] ) ), true );
$line_item_totals = json_decode ( sanitize_text_field ( wp_unslash ( $_POST [ 'line_item_totals' ] ) ), true );
$line_item_tax_totals = json_decode ( sanitize_text_field ( wp_unslash ( $_POST [ 'line_item_tax_totals' ] ) ), true );
2016-11-24 17:50:24 +00:00
$api_refund = 'true' === $_POST [ 'api_refund' ];
$restock_refunded_items = 'true' === $_POST [ 'restock_refunded_items' ];
2014-09-12 09:09:22 +00:00
$refund = false ;
2015-01-02 12:43:47 +00:00
$response_data = array ();
2014-05-31 07:32:22 +00:00
2014-07-10 13:49:04 +00:00
try {
2014-08-15 12:29:21 +00:00
$order = wc_get_order ( $order_id );
2014-07-25 10:29:24 +00:00
$order_items = $order -> get_items ();
2016-03-03 13:40:50 +00:00
$max_refund = wc_format_decimal ( $order -> get_total () - $order -> get_total_refunded (), wc_get_price_decimals () );
2014-07-10 13:49:04 +00:00
2015-06-15 20:19:52 +00:00
if ( ! $refund_amount || $max_refund < $refund_amount || 0 > $refund_amount ) {
2014-07-10 13:49:04 +00:00
throw new exception ( __ ( 'Invalid refund amount' , 'woocommerce' ) );
}
2014-07-16 18:41:18 +00:00
2017-09-28 15:17:13 +00:00
if ( $refunded_amount !== wc_format_decimal ( $order -> get_total_refunded (), wc_get_price_decimals () ) ) {
throw new exception ( __ ( 'Error processing refund. Please try again.' , 'woocommerce' ) );
}
// Prepare line items which we are refunding.
2014-07-24 14:34:14 +00:00
$line_items = array ();
$item_ids = array_unique ( array_merge ( array_keys ( $line_item_qtys , $line_item_totals ) ) );
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' ) ) {
2015-01-02 12:43:47 +00:00
$response_data [ 'status' ] = 'fully_refunded' ;
}
wp_send_json_success ( $response_data );
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
}
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' );
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
}
2016-03-23 16:32:12 +00:00
$refund_ids = array_map ( 'absint' , is_array ( $_POST [ 'refund_id' ] ) ? $_POST [ 'refund_id' ] : array ( $_POST [ 'refund_id' ] ) );
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 .
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
}
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' ) );
}
$key_id = absint ( $_POST [ 'key_id' ] );
2015-09-07 15:29:03 +00:00
$description = sanitize_text_field ( wp_unslash ( $_POST [ 'description' ] ) );
2015-06-08 22:41:35 +00:00
$permissions = ( in_array ( $_POST [ 'permissions' ], array ( 'read' , 'write' , 'read_write' ) ) ) ? sanitize_text_field ( $_POST [ 'permissions' ] ) : 'read' ;
$user_id = absint ( $_POST [ 'user' ] );
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' )
);
$data [ 'consumer_key' ] = '' ;
$data [ 'consumer_secret' ] = '' ;
$data [ 'message' ] = __ ( 'API Key updated successfully.' , 'woocommerce' );
} 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
)
);
2015-06-08 23:22:49 +00:00
$key_id = $wpdb -> insert_id ;
2015-06-08 22:41:35 +00:00
$data [ 'consumer_key' ] = $consumer_key ;
$data [ 'consumer_secret' ] = $consumer_secret ;
2017-04-26 12:51:53 +00:00
$data [ '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' );
2018-04-12 15:59:42 +00:00
$data [ '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
}
wp_send_json_success ( $data );
} catch ( Exception $e ) {
wp_send_json_error ( array ( 'message' => $e -> getMessage () ) );
}
}
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
}
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
// 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' ] );
$post = get_post ( $product_id );
$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 ) {
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 );
2017-07-17 10:10:52 +00:00
$variation_data = array_merge ( array_map ( 'maybe_unserialize' , get_post_custom ( $variation_id ) ), wc_get_product_variation_attributes ( $variation_id ) ); // kept for BW compatibility.
2018-02-22 15:37:01 +00:00
include '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' );
// 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 );
2015-07-27 17:16:52 +00:00
if ( $errors = WC_Admin_Meta_Boxes :: $meta_box_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>' ;
}
2015-07-29 22:56:33 +00:00
echo '<button type="button" class="notice-dismiss"><span class="screen-reader-text">' . __ ( '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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2017-04-06 20:11:04 +00:00
* @ access private
* @ used - by bulk_edit_variations
* @ param array $variations
* @ param array $data
*/
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
*
2017-04-06 20:11:04 +00:00
* @ access private
* @ used - by bulk_edit_variations
* @ param array $variations
* @ param array $data
*/
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
*
2017-11-14 22:18:03 +00:00
* @ access private
* @ used - by bulk_edit_variations
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2015-07-14 10:39:48 +00:00
* @ param array $variations
* @ param array $data
*/
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
*
2015-07-14 10:39:48 +00:00
* @ access private
2016-06-07 13:19:36 +00:00
* @ used - by bulk_edit_variations
2018-02-22 15:37:01 +00:00
* @ param array $variations
2015-07-14 10:39:48 +00:00
* @ param string $operator + or -
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
* @ param string $field price being adjusted _regular_price or _sale_price
2015-07-14 10:39:48 +00:00
* @ param string $value Price or Percent
*/
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 ) );
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 += ( ( $field_value / 100 ) * $percent ) * " { $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
*
2015-07-14 10:39:48 +00:00
* @ access private
2018-02-22 15:37:01 +00:00
* @ param array $variations
2015-07-16 19:29:01 +00:00
* @ param string $field
* @ param string $value
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
*
2016-11-23 06:47:26 +00:00
* @ access private
2018-02-22 15:37:01 +00:00
* @ param array $variations
2016-11-23 06:47:26 +00:00
* @ param string $field
*/
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
2015-07-14 10:39:48 +00:00
*/
public static function bulk_edit_variations () {
ob_start ();
check_ajax_referer ( 'bulk-edit-variations' , 'security' );
// Check permissions again and make sure we have what we need
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' ] );
$bulk_action = wc_clean ( $_POST [ 'bulk_action' ] );
$data = ! empty ( $_POST [ 'data' ] ) ? array_map ( 'wc_clean' , $_POST [ 'data' ] ) : array ();
$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 () {
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
}
2016-02-22 15:19:44 +00:00
$current_class = ! empty ( $_POST [ 'current_class' ] ) ? $_POST [ 'current_class' ] : '' ; // This is sanitized seven lines later.
2015-08-13 21:49:59 +00:00
if ( ! wp_verify_nonce ( $_POST [ 'wc_tax_nonce' ], 'wc_tax_nonce-class:' . $current_class ) ) {
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 );
// Check User Caps
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
}
$changes = $_POST [ 'changes' ];
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 (
$data , array (
'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' ] ) ) {
WC_Tax :: _update_tax_rate_cities ( $tax_rate_id , array_map ( 'wc_clean' , $data [ 'city' ] ) );
}
}
2018-01-18 17:47:26 +00:00
WC_Cache_Helper :: incr_cache_prefix ( 'taxes' );
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 ),
)
);
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
}
if ( ! wp_verify_nonce ( $_POST [ 'wc_shipping_zones_nonce' ], 'wc_shipping_zones_nonce' ) ) {
wp_send_json_error ( 'bad_nonce' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-10 11:55:03 +00:00
}
// Check User Caps
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
}
$changes = $_POST [ 'changes' ];
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 (
$data , array (
'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
}
if ( ! wp_verify_nonce ( $_POST [ 'wc_shipping_zones_nonce' ], 'wc_shipping_zones_nonce' ) ) {
wp_send_json_error ( 'bad_nonce' );
2018-02-26 17:27:25 +00:00
wp_die ();
2015-12-16 15:16:52 +00:00
}
// Check User Caps
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
}
2016-09-24 02:22:57 +00:00
$zone_id = wc_clean ( $_POST [ 'zone_id' ] );
$zone = new WC_Shipping_Zone ( $zone_id );
2015-12-16 15:16:52 +00:00
$instance_id = $zone -> add_shipping_method ( wc_clean ( $_POST [ 'method_id' ] ) );
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
}
if ( ! wp_verify_nonce ( $_POST [ 'wc_shipping_zones_nonce' ], 'wc_shipping_zones_nonce' ) ) {
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 ;
2016-09-24 02:22:57 +00:00
$zone_id = wc_clean ( $_POST [ 'zone_id' ] );
2015-12-15 17:48:03 +00:00
$zone = new WC_Shipping_Zone ( $zone_id );
2016-10-10 17:41:07 +00:00
$changes = $_POST [ 'changes' ];
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 ) {
// Each posted location will be in the format type:code
$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 (
$data , array (
'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
}
if ( ! wp_verify_nonce ( $_POST [ 'wc_shipping_zones_nonce' ], 'wc_shipping_zones_nonce' ) ) {
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 );
2016-04-20 14:02:41 +00:00
$shipping_method -> set_post_data ( $_POST [ 'data' ] );
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
}
if ( ! wp_verify_nonce ( $_POST [ 'wc_shipping_classes_nonce' ], 'wc_shipping_classes_nonce' ) ) {
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
}
$changes = $_POST [ 'changes' ];
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 () {
if ( current_user_can ( 'manage_woocommerce' ) && check_ajax_referer ( 'woocommerce-toggle-payment-gateway-enabled' , 'security' ) ) {
// 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 ();