fixed some coding standards in includes/class-wc-ajax.php
This commit is contained in:
parent
aa24199d82
commit
e65f41f014
|
@ -61,10 +61,11 @@ class WC_AJAX {
|
|||
foreach ( $ajax_events as $ajax_event => $nopriv ) {
|
||||
add_action( 'wp_ajax_woocommerce_' . $ajax_event, array( $this, $ajax_event ) );
|
||||
|
||||
if ( $nopriv )
|
||||
if ( $nopriv ) {
|
||||
add_action( 'wp_ajax_nopriv_woocommerce_' . $ajax_event, array( $this, $ajax_event ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output headers for JSON requests
|
||||
|
@ -127,7 +128,9 @@ class WC_AJAX {
|
|||
|
||||
check_ajax_referer( 'update-shipping-method', 'security' );
|
||||
|
||||
if ( ! defined('WOOCOMMERCE_CART') ) define( 'WOOCOMMERCE_CART', true );
|
||||
if ( ! defined('WOOCOMMERCE_CART') ) {
|
||||
define( 'WOOCOMMERCE_CART', true );
|
||||
}
|
||||
|
||||
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
|
||||
|
||||
|
@ -153,10 +156,11 @@ class WC_AJAX {
|
|||
|
||||
check_ajax_referer( 'update-order-review', 'security' );
|
||||
|
||||
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) )
|
||||
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
|
||||
define( 'WOOCOMMERCE_CHECKOUT', true );
|
||||
}
|
||||
|
||||
if ( sizeof( WC()->cart->get_cart() ) == 0 ) {
|
||||
if ( 0 == sizeof( WC()->cart->get_cart() ) ) {
|
||||
echo '<div class="woocommerce-error">' . __( 'Sorry, your session has expired.', 'woocommerce' ) . ' <a href="' . home_url() . '" class="wc-backward">' . __( 'Return to homepage', 'woocommerce' ) . '</a></div>';
|
||||
die();
|
||||
}
|
||||
|
@ -165,70 +169,90 @@ class WC_AJAX {
|
|||
|
||||
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
|
||||
|
||||
if ( isset( $_POST['shipping_method'] ) && is_array( $_POST['shipping_method'] ) )
|
||||
foreach ( $_POST['shipping_method'] as $i => $value )
|
||||
if ( isset( $_POST['shipping_method'] ) && is_array( $_POST['shipping_method'] ) ) {
|
||||
foreach ( $_POST['shipping_method'] as $i => $value ) {
|
||||
$chosen_shipping_methods[ $i ] = wc_clean( $value );
|
||||
}
|
||||
}
|
||||
|
||||
WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
|
||||
WC()->session->set( 'chosen_payment_method', empty( $_POST['payment_method'] ) ? '' : $_POST['payment_method'] );
|
||||
|
||||
if ( isset( $_POST['country'] ) )
|
||||
if ( isset( $_POST['country'] ) ) {
|
||||
WC()->customer->set_country( $_POST['country'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['state'] ) )
|
||||
if ( isset( $_POST['state'] ) ) {
|
||||
WC()->customer->set_state( $_POST['state'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['postcode'] ) )
|
||||
if ( isset( $_POST['postcode'] ) ) {
|
||||
WC()->customer->set_postcode( $_POST['postcode'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['city'] ) )
|
||||
if ( isset( $_POST['city'] ) ) {
|
||||
WC()->customer->set_city( $_POST['city'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['address'] ) )
|
||||
if ( isset( $_POST['address'] ) ) {
|
||||
WC()->customer->set_address( $_POST['address'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['address_2'] ) )
|
||||
if ( isset( $_POST['address_2'] ) ) {
|
||||
WC()->customer->set_address_2( $_POST['address_2'] );
|
||||
}
|
||||
|
||||
if ( wc_ship_to_billing_address_only() ) {
|
||||
|
||||
if ( isset( $_POST['country'] ) )
|
||||
if ( isset( $_POST['country'] ) ) {
|
||||
WC()->customer->set_shipping_country( $_POST['country'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['state'] ) )
|
||||
if ( isset( $_POST['state'] ) ) {
|
||||
WC()->customer->set_shipping_state( $_POST['state'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['postcode'] ) )
|
||||
if ( isset( $_POST['postcode'] ) ) {
|
||||
WC()->customer->set_shipping_postcode( $_POST['postcode'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['city'] ) )
|
||||
if ( isset( $_POST['city'] ) ) {
|
||||
WC()->customer->set_shipping_city( $_POST['city'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['address'] ) )
|
||||
if ( isset( $_POST['address'] ) ) {
|
||||
WC()->customer->set_shipping_address( $_POST['address'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['address_2'] ) )
|
||||
if ( isset( $_POST['address_2'] ) ) {
|
||||
WC()->customer->set_shipping_address_2( $_POST['address_2'] );
|
||||
}
|
||||
} else {
|
||||
|
||||
if ( isset( $_POST['s_country'] ) )
|
||||
if ( isset( $_POST['s_country'] ) ) {
|
||||
WC()->customer->set_shipping_country( $_POST['s_country'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['s_state'] ) )
|
||||
if ( isset( $_POST['s_state'] ) ) {
|
||||
WC()->customer->set_shipping_state( $_POST['s_state'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['s_postcode'] ) )
|
||||
if ( isset( $_POST['s_postcode'] ) ) {
|
||||
WC()->customer->set_shipping_postcode( $_POST['s_postcode'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['s_city'] ) )
|
||||
if ( isset( $_POST['s_city'] ) ) {
|
||||
WC()->customer->set_shipping_city( $_POST['s_city'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['s_address'] ) )
|
||||
if ( isset( $_POST['s_address'] ) ) {
|
||||
WC()->customer->set_shipping_address( $_POST['s_address'] );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['s_address_2'] ) )
|
||||
if ( isset( $_POST['s_address_2'] ) ) {
|
||||
WC()->customer->set_shipping_address_2( $_POST['s_address_2'] );
|
||||
}
|
||||
}
|
||||
|
||||
WC()->cart->calculate_totals();
|
||||
|
||||
|
@ -276,8 +300,9 @@ class WC_AJAX {
|
|||
* Process ajax checkout form
|
||||
*/
|
||||
public function checkout() {
|
||||
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) )
|
||||
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
|
||||
define( 'WOOCOMMERCE_CHECKOUT', true );
|
||||
}
|
||||
|
||||
$woocommerce_checkout = WC()->checkout();
|
||||
$woocommerce_checkout->process_checkout();
|
||||
|
@ -322,10 +347,18 @@ class WC_AJAX {
|
|||
* Mark an order as complete
|
||||
*/
|
||||
public function mark_order_complete() {
|
||||
if ( !current_user_can('edit_shop_orders') ) wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce' ) );
|
||||
if ( !check_admin_referer('woocommerce-mark-order-complete')) wp_die( __( 'You have taken too long. Please go back and retry.', 'woocommerce' ) );
|
||||
$order_id = isset($_GET['order_id']) && (int) $_GET['order_id'] ? (int) $_GET['order_id'] : '';
|
||||
if (!$order_id) die;
|
||||
if ( ! current_user_can( 'edit_shop_orders' ) ) {
|
||||
wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
if ( ! check_admin_referer( 'woocommerce-mark-order-complete' ) ) {
|
||||
wp_die( __( 'You have taken too long. Please go back and retry.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
$order_id = isset( $_GET['order_id'] ) && (int) $_GET['order_id'] ? (int) $_GET['order_id'] : '';
|
||||
if ( ! $order_id ) {
|
||||
die();
|
||||
}
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order->update_status( 'completed' );
|
||||
|
@ -339,10 +372,18 @@ class WC_AJAX {
|
|||
* Mark an order as processing
|
||||
*/
|
||||
public function mark_order_processing() {
|
||||
if ( !current_user_can('edit_shop_orders') ) wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce' ) );
|
||||
if ( !check_admin_referer('woocommerce-mark-order-processing')) wp_die( __( 'You have taken too long. Please go back and retry.', 'woocommerce' ) );
|
||||
$order_id = isset($_GET['order_id']) && (int) $_GET['order_id'] ? (int) $_GET['order_id'] : '';
|
||||
if (!$order_id) die;
|
||||
if ( ! current_user_can( 'edit_shop_orders' ) ) {
|
||||
wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
if ( ! check_admin_referer( 'woocommerce-mark-order-processing' ) ) {
|
||||
wp_die( __( 'You have taken too long. Please go back and retry.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
$order_id = isset( $_GET['order_id'] ) && (int) $_GET['order_id'] ? (int) $_GET['order_id'] : '';
|
||||
if ( ! $order_id ) {
|
||||
die();
|
||||
}
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order->update_status( 'processing' );
|
||||
|
@ -368,12 +409,12 @@ class WC_AJAX {
|
|||
|
||||
$result = wp_insert_term( $term, $taxonomy );
|
||||
|
||||
if ( is_wp_error($result) ) {
|
||||
echo json_encode(array(
|
||||
if ( is_wp_error( $result ) ) {
|
||||
echo json_encode( array(
|
||||
'error' => $result->get_error_message()
|
||||
));
|
||||
} else {
|
||||
echo json_encode(array(
|
||||
echo json_encode( array(
|
||||
'term_id' => $result['term_id'],
|
||||
'name' => $term,
|
||||
'slug' => sanitize_title( $term ),
|
||||
|
@ -390,10 +431,14 @@ class WC_AJAX {
|
|||
public function remove_variation() {
|
||||
|
||||
check_ajax_referer( 'delete-variation', 'security' );
|
||||
|
||||
$variation_id = intval( $_POST['variation_id'] );
|
||||
$variation = get_post($variation_id);
|
||||
if ( $variation && $variation->post_type == "product_variation" )
|
||||
$variation = get_post( $variation_id );
|
||||
|
||||
if ( $variation && 'product_variation' == $variation->post_type ) {
|
||||
wp_delete_post( $variation_id );
|
||||
}
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
|
@ -403,12 +448,17 @@ class WC_AJAX {
|
|||
public function remove_variations() {
|
||||
|
||||
check_ajax_referer( 'delete-variations', 'security' );
|
||||
|
||||
$variation_ids = (array) $_POST['variation_ids'];
|
||||
|
||||
foreach ( $variation_ids as $variation_id ) {
|
||||
$variation = get_post($variation_id);
|
||||
if ( $variation && $variation->post_type == "product_variation" )
|
||||
$variation = get_post( $variation_id );
|
||||
|
||||
if ( $variation && 'product_variation' == $variation->post_type ) {
|
||||
wp_delete_post( $variation_id );
|
||||
}
|
||||
}
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
|
@ -431,20 +481,22 @@ class WC_AJAX {
|
|||
$attribute_names = array_map( 'stripslashes', $data['attribute_names'] );
|
||||
$attribute_values = isset( $data['attribute_values'] ) ? $data['attribute_values'] : array();
|
||||
|
||||
if ( isset( $data['attribute_visibility'] ) )
|
||||
if ( isset( $data['attribute_visibility'] ) ) {
|
||||
$attribute_visibility = $data['attribute_visibility'];
|
||||
}
|
||||
|
||||
if ( isset( $data['attribute_variation'] ) )
|
||||
if ( isset( $data['attribute_variation'] ) ) {
|
||||
$attribute_variation = $data['attribute_variation'];
|
||||
}
|
||||
|
||||
$attribute_is_taxonomy = $data['attribute_is_taxonomy'];
|
||||
$attribute_position = $data['attribute_position'];
|
||||
|
||||
$attribute_names_count = sizeof( $attribute_names );
|
||||
|
||||
for ( $i=0; $i < $attribute_names_count; $i++ ) {
|
||||
if ( ! $attribute_names[ $i ] )
|
||||
for ( $i = 0; $i < $attribute_names_count; $i++ ) {
|
||||
if ( ! $attribute_names[ $i ] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_visible = isset( $attribute_visibility[ $i ] ) ? 1 : 0;
|
||||
$is_variation = isset( $attribute_variation[ $i ] ) ? 1 : 0;
|
||||
|
@ -471,8 +523,9 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
// Update post terms
|
||||
if ( taxonomy_exists( $attribute_names[ $i ] ) )
|
||||
if ( taxonomy_exists( $attribute_names[ $i ] ) ) {
|
||||
wp_set_object_terms( $post_id, $values, $attribute_names[ $i ] );
|
||||
}
|
||||
|
||||
if ( $values ) {
|
||||
// Add attribute to array, but don't set values
|
||||
|
@ -507,7 +560,10 @@ class WC_AJAX {
|
|||
|
||||
if ( ! function_exists( 'attributes_cmp' ) ) {
|
||||
function attributes_cmp( $a, $b ) {
|
||||
if ( $a['position'] == $b['position'] ) return 0;
|
||||
if ( $a['position'] == $b['position'] ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ( $a['position'] < $b['position'] ) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
@ -555,8 +611,12 @@ class WC_AJAX {
|
|||
$tax_class_options = array();
|
||||
$tax_class_options['parent'] =__( 'Same as parent', 'woocommerce' );
|
||||
$tax_class_options[''] = __( 'Standard', 'woocommerce' );
|
||||
if ($tax_classes) foreach ( $tax_classes as $class )
|
||||
$tax_class_options[sanitize_title($class)] = $class;
|
||||
|
||||
if ( $tax_classes ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$tax_class_options[ sanitize_title( $class ) ] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
// Get parent data
|
||||
$parent_data = array(
|
||||
|
@ -571,17 +631,21 @@ class WC_AJAX {
|
|||
'tax_class' => get_post_meta( $post_id, '_tax_class', true )
|
||||
);
|
||||
|
||||
if ( ! $parent_data['weight'] )
|
||||
if ( ! $parent_data['weight'] ) {
|
||||
$parent_data['weight'] = '0.00';
|
||||
}
|
||||
|
||||
if ( ! $parent_data['length'] )
|
||||
if ( ! $parent_data['length'] ) {
|
||||
$parent_data['length'] = '0';
|
||||
}
|
||||
|
||||
if ( ! $parent_data['width'] )
|
||||
if ( ! $parent_data['width'] ) {
|
||||
$parent_data['width'] = '0';
|
||||
}
|
||||
|
||||
if ( ! $parent_data['height'] )
|
||||
if ( ! $parent_data['height'] ) {
|
||||
$parent_data['height'] = '0';
|
||||
}
|
||||
|
||||
$_tax_class = '';
|
||||
$_downloadable_files = '';
|
||||
|
@ -609,16 +673,19 @@ class WC_AJAX {
|
|||
|
||||
$post_id = intval( $_POST['post_id'] );
|
||||
|
||||
if ( ! $post_id ) die();
|
||||
if ( ! $post_id ) {
|
||||
die();
|
||||
}
|
||||
|
||||
$variations = array();
|
||||
|
||||
$_product = get_product( $post_id, array( 'product_type' => 'variable' ) );
|
||||
|
||||
// Put variation attributes into an array
|
||||
foreach ( $_product->get_attributes() as $attribute ) {
|
||||
|
||||
if ( ! $attribute['is_variation'] ) continue;
|
||||
if ( ! $attribute['is_variation'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attribute_field_name = 'attribute_' . sanitize_title( $attribute['name'] );
|
||||
|
||||
|
@ -634,7 +701,9 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
// Quit out if none were found
|
||||
if ( sizeof( $variations ) == 0 ) die();
|
||||
if ( sizeof( $variations ) == 0 ) {
|
||||
die();
|
||||
}
|
||||
|
||||
// Get existing variations so we don't create duplicates
|
||||
$available_variations = array();
|
||||
|
@ -659,6 +728,7 @@ class WC_AJAX {
|
|||
|
||||
// Now find all combinations and create posts
|
||||
if ( ! function_exists( 'array_cartesian' ) ) {
|
||||
|
||||
/**
|
||||
* @param array $input
|
||||
* @return array
|
||||
|
@ -689,7 +759,7 @@ class WC_AJAX {
|
|||
// Store all items to be added to $product here; adding them on the spot
|
||||
// inside the foreach will result in an infinite loop
|
||||
$append = array();
|
||||
foreach( $result as &$product ) {
|
||||
foreach ( $result as &$product ) {
|
||||
// Do step 1 above. array_shift is not the most efficient, but it
|
||||
// allows us to iterate over the rest of the items with a simple
|
||||
// foreach, making the code short and familiar.
|
||||
|
@ -700,7 +770,7 @@ class WC_AJAX {
|
|||
$copy = $product;
|
||||
|
||||
// Do step 2 above.
|
||||
foreach( $values as $item ) {
|
||||
foreach ( $values as $item ) {
|
||||
$copy[ $key ] = $item;
|
||||
$append[] = $copy;
|
||||
}
|
||||
|
@ -725,8 +795,9 @@ class WC_AJAX {
|
|||
foreach ( $possible_variations as $variation ) {
|
||||
|
||||
// Check if variation already exists
|
||||
if ( in_array( $variation, $available_variations ) )
|
||||
if ( in_array( $variation, $available_variations ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$variation_id = wp_insert_post( $variation_post_data );
|
||||
|
||||
|
@ -740,9 +811,10 @@ class WC_AJAX {
|
|||
|
||||
do_action( 'product_variation_linked', $variation_id );
|
||||
|
||||
if ( $added > WC_MAX_LINKED_VARIATIONS )
|
||||
if ( $added > WC_MAX_LINKED_VARIATIONS ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wc_delete_product_transients( $post_id );
|
||||
|
||||
|
@ -796,8 +868,9 @@ class WC_AJAX {
|
|||
$product = get_product( $product_id );
|
||||
$files = $product->get_files();
|
||||
|
||||
if ( ! $order->billing_email )
|
||||
if ( ! $order->billing_email ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( $files ) {
|
||||
foreach ( $files as $download_id => $file ) {
|
||||
|
@ -869,16 +942,17 @@ class WC_AJAX {
|
|||
$order_id = absint( $_POST['order_id'] );
|
||||
|
||||
// Find the item
|
||||
if ( ! is_numeric( $item_to_add ) )
|
||||
if ( ! is_numeric( $item_to_add ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
$post = get_post( $item_to_add );
|
||||
|
||||
if ( ! $post || ( $post->post_type !== 'product' && $post->post_type !== 'product_variation' ) )
|
||||
if ( ! $post || ( 'product' !== $post->post_type && 'product_variation' !== $post->post_type ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
$_product = get_product( $post->ID );
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$class = 'new_row';
|
||||
|
||||
|
@ -999,8 +1073,9 @@ class WC_AJAX {
|
|||
foreach ( $order_items as $item_id => $order_item ) {
|
||||
|
||||
// Only reduce checked items
|
||||
if ( ! in_array( $item_id, $order_item_ids ) )
|
||||
if ( ! in_array( $item_id, $order_item_ids ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$_product = $order->get_product_from_item( $order_item );
|
||||
|
||||
|
@ -1016,8 +1091,9 @@ class WC_AJAX {
|
|||
|
||||
do_action( 'woocommerce_reduce_order_stock', $order );
|
||||
|
||||
if ( empty( $return ) )
|
||||
if ( empty( $return ) ) {
|
||||
$return[] = __( 'No products had their stock reduced - they may not have stock management enabled.', 'woocommerce' );
|
||||
}
|
||||
|
||||
echo implode( ', ', $return );
|
||||
}
|
||||
|
@ -1045,8 +1121,9 @@ class WC_AJAX {
|
|||
foreach ( $order_items as $item_id => $order_item ) {
|
||||
|
||||
// Only reduce checked items
|
||||
if ( ! in_array( $item_id, $order_item_ids ) )
|
||||
if ( ! in_array( $item_id, $order_item_ids ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$_product = $order->get_product_from_item( $order_item );
|
||||
|
||||
|
@ -1063,8 +1140,9 @@ class WC_AJAX {
|
|||
|
||||
do_action( 'woocommerce_restore_order_stock', $order );
|
||||
|
||||
if ( empty( $return ) )
|
||||
if ( empty( $return ) ) {
|
||||
$return[] = __( 'No products had their stock increased - they may not have stock management enabled.', 'woocommerce' );
|
||||
}
|
||||
|
||||
echo implode( ', ', $return );
|
||||
}
|
||||
|
@ -1083,9 +1161,7 @@ class WC_AJAX {
|
|||
$meta_id = wc_add_order_item_meta( absint( $_POST['order_item_id'] ), __( 'Name', 'woocommerce' ), __( 'Value', 'woocommerce' ) );
|
||||
|
||||
if ( $meta_id ) {
|
||||
|
||||
echo '<tr data-meta_id="' . esc_attr( $meta_id ) . '"><td><input type="text" name="meta_key[' . $meta_id . ']" /><textarea name="meta_value[' . $meta_id . ']"></textarea></td><td width="1%"><button class="remove_order_item_meta button">×</button></td></tr>';
|
||||
|
||||
}
|
||||
|
||||
die();
|
||||
|
@ -1117,16 +1193,13 @@ class WC_AJAX {
|
|||
$this->json_headers();
|
||||
|
||||
$tax = new WC_Tax();
|
||||
|
||||
$taxes = $tax_rows = $item_taxes = $shipping_taxes = array();
|
||||
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$order = new WC_Order( $order_id );
|
||||
$country = strtoupper( esc_attr( $_POST['country'] ) );
|
||||
$state = strtoupper( esc_attr( $_POST['state'] ) );
|
||||
$postcode = strtoupper( esc_attr( $_POST['postcode'] ) );
|
||||
$city = sanitize_title( esc_attr( $_POST['city'] ) );
|
||||
|
||||
$items = isset( $_POST['items'] ) ? $_POST['items'] : array();
|
||||
$shipping = $_POST['shipping'];
|
||||
$item_tax = 0;
|
||||
|
@ -1141,8 +1214,9 @@ class WC_AJAX {
|
|||
$tax_class = sanitize_text_field( $item['tax_class'] );
|
||||
$product_id = $order->get_item_meta( $item_id, '_product_id', true );
|
||||
|
||||
if ( ! $item_id || $tax_class == '0' )
|
||||
if ( ! $item_id || '0' == $tax_class ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get product details
|
||||
if ( get_post_type( $product_id ) == 'product' ) {
|
||||
|
@ -1153,7 +1227,7 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
// Only calc if taxable
|
||||
if ( $item_tax_status == 'taxable' ) {
|
||||
if ( 'taxable' == $item_tax_status ) {
|
||||
|
||||
$tax_rates = $tax->find_rates( array(
|
||||
'country' => $country,
|
||||
|
@ -1168,11 +1242,13 @@ class WC_AJAX {
|
|||
$line_subtotal_tax = array_sum( $line_subtotal_taxes );
|
||||
$line_tax = array_sum( $line_taxes );
|
||||
|
||||
if ( $line_subtotal_tax < 0 )
|
||||
if ( $line_subtotal_tax < 0 ) {
|
||||
$line_subtotal_tax = 0;
|
||||
}
|
||||
|
||||
if ( $line_tax < 0 )
|
||||
if ( $line_tax < 0 ) {
|
||||
$line_tax = 0;
|
||||
}
|
||||
|
||||
$item_taxes[ $item_id ] = array(
|
||||
'line_subtotal_tax' => wc_format_localized_price( $line_subtotal_tax ),
|
||||
|
@ -1182,9 +1258,10 @@ class WC_AJAX {
|
|||
$item_tax += $line_tax;
|
||||
|
||||
// Sum the item taxes
|
||||
foreach ( array_keys( $taxes + $line_taxes ) as $key )
|
||||
foreach ( array_keys( $taxes + $line_taxes ) as $key ) {
|
||||
$taxes[ $key ] = ( isset( $line_taxes[ $key ] ) ? $line_taxes[ $key ] : 0 ) + ( isset( $taxes[ $key ] ) ? $taxes[ $key ] : 0 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1200,10 +1277,13 @@ class WC_AJAX {
|
|||
'tax_class' => ''
|
||||
) );
|
||||
|
||||
if ( $tax_rates )
|
||||
foreach ( $tax_rates as $key => $rate )
|
||||
if ( isset( $rate['shipping'] ) && $rate['shipping'] == 'yes' )
|
||||
if ( $tax_rates ) {
|
||||
foreach ( $tax_rates as $key => $rate ) {
|
||||
if ( isset( $rate['shipping'] ) && 'yes' == $rate['shipping'] ) {
|
||||
$matched_tax_rates[ $key ] = $rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$shipping_taxes = $tax->calc_shipping_tax( $shipping, $matched_tax_rates );
|
||||
$shipping_tax = $tax->round( array_sum( $shipping_taxes ) );
|
||||
|
@ -1242,8 +1322,9 @@ class WC_AJAX {
|
|||
$item['tax_amount'] = wc_format_decimal( isset( $taxes[ $key ] ) ? $taxes[ $key ] : 0 );
|
||||
$item['shipping_tax_amount'] = wc_format_decimal( isset( $shipping_taxes[ $key ] ) ? $shipping_taxes[ $key ] : 0 );
|
||||
|
||||
if ( ! $item['label'] )
|
||||
if ( ! $item['label'] ) {
|
||||
$item['label'] = WC()->countries->tax_or_vat();
|
||||
}
|
||||
|
||||
// Add line item
|
||||
$item_id = wc_add_order_item( $order_id, array(
|
||||
|
@ -1295,7 +1376,9 @@ class WC_AJAX {
|
|||
$comment_id = $order->add_order_note( $note, $is_customer_note );
|
||||
|
||||
echo '<li rel="' . esc_attr( $comment_id ) . '" class="note ';
|
||||
if ( $is_customer_note ) echo 'customer-note';
|
||||
if ( $is_customer_note ) {
|
||||
echo 'customer-note';
|
||||
}
|
||||
echo '"><div class="note_content">';
|
||||
echo wpautop( wptexturize( $note ) );
|
||||
echo '</div><p class="meta"><a href="#" class="delete_note">'.__( 'Delete note', 'woocommerce' ).'</a></p>';
|
||||
|
@ -1315,9 +1398,9 @@ class WC_AJAX {
|
|||
|
||||
$note_id = (int) $_POST['note_id'];
|
||||
|
||||
if ($note_id>0) :
|
||||
if ( $note_id > 0 ) {
|
||||
wp_delete_comment( $note_id );
|
||||
endif;
|
||||
}
|
||||
|
||||
// Quit out
|
||||
die();
|
||||
|
@ -1337,7 +1420,9 @@ class WC_AJAX {
|
|||
|
||||
$term = (string) wc_clean( stripslashes( $_GET['term'] ) );
|
||||
|
||||
if (empty($term)) die();
|
||||
if ( empty( $term ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( is_numeric( $term ) ) {
|
||||
|
||||
|
@ -1371,7 +1456,7 @@ class WC_AJAX {
|
|||
'fields' => 'ids'
|
||||
);
|
||||
|
||||
$posts = array_unique(array_merge( get_posts( $args ), get_posts( $args2 ), get_posts( $args3 ) ));
|
||||
$posts = array_unique( array_merge( get_posts( $args ), get_posts( $args2 ), get_posts( $args3 ) ) );
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -1397,18 +1482,18 @@ class WC_AJAX {
|
|||
'fields' => 'ids'
|
||||
);
|
||||
|
||||
$posts = array_unique(array_merge( get_posts( $args ), get_posts( $args2 ) ));
|
||||
$posts = array_unique( array_merge( get_posts( $args ), get_posts( $args2 ) ) );
|
||||
|
||||
}
|
||||
|
||||
$found_products = array();
|
||||
|
||||
if ( $posts ) foreach ( $posts as $post ) {
|
||||
|
||||
if ( $posts ) {
|
||||
foreach ( $posts as $post ) {
|
||||
$product = get_product( $post );
|
||||
|
||||
$found_products[ $post ] = $product->get_formatted_name();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$found_products = apply_filters( 'woocommerce_json_search_found_products', $found_products );
|
||||
|
@ -1440,8 +1525,9 @@ class WC_AJAX {
|
|||
|
||||
$term = wc_clean( stripslashes( $_GET['term'] ) );
|
||||
|
||||
if ( empty( $term ) )
|
||||
if ( empty( $term ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
$default = isset( $_GET['default'] ) ? $_GET['default'] : __( 'Guest', 'woocommerce' );
|
||||
|
||||
|
@ -1494,12 +1580,16 @@ class WC_AJAX {
|
|||
),
|
||||
's' => $term
|
||||
);
|
||||
|
||||
$posts = get_posts( $args );
|
||||
$found_products = array();
|
||||
if ( $posts ) foreach ( $posts as $post ) {
|
||||
|
||||
if ( $posts ) {
|
||||
foreach ( $posts as $post ) {
|
||||
$product = get_product( $post->ID );
|
||||
$found_products[ $post->ID ] = $product->get_formatted_name();
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode( $found_products );
|
||||
die();
|
||||
|
@ -1526,19 +1616,21 @@ class WC_AJAX {
|
|||
global $wpdb;
|
||||
|
||||
$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;
|
||||
$next_id = isset( $_POST['nextid'] ) && (int) $_POST['nextid'] ? (int) $_POST['nextid'] : null;
|
||||
$taxonomy = isset( $_POST['thetaxonomy'] ) ? esc_attr( $_POST['thetaxonomy'] ) : null;
|
||||
$term = get_term_by('id', $id, $taxonomy);
|
||||
|
||||
if ( !$id || !$term || !$taxonomy ) die(0);
|
||||
if ( ! $id || ! $term || ! $taxonomy ) {
|
||||
die(0);
|
||||
}
|
||||
|
||||
wc_reorder_terms( $term, $next_id, $taxonomy );
|
||||
|
||||
$children = get_terms($taxonomy, "child_of=$id&menu_order=ASC&hide_empty=0");
|
||||
$children = get_terms( $taxonomy, "child_of=$id&menu_order=ASC&hide_empty=0" );
|
||||
|
||||
if ( $term && sizeof($children) ) {
|
||||
if ( $term && sizeof( $children ) ) {
|
||||
echo 'children';
|
||||
die;
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1551,12 +1643,14 @@ class WC_AJAX {
|
|||
global $wpdb;
|
||||
|
||||
// check permissions again and make sure we have what we need
|
||||
if ( ! current_user_can('edit_products') || empty( $_POST['id'] ) || ( ! isset( $_POST['previd'] ) && ! isset( $_POST['nextid'] ) ) )
|
||||
if ( ! current_user_can('edit_products') || empty( $_POST['id'] ) || ( ! isset( $_POST['previd'] ) && ! isset( $_POST['nextid'] ) ) ) {
|
||||
die(-1);
|
||||
}
|
||||
|
||||
// real post?
|
||||
if ( ! $post = get_post( $_POST['id'] ) )
|
||||
if ( ! $post = get_post( $_POST['id'] ) ) {
|
||||
die(-1);
|
||||
}
|
||||
|
||||
$this->json_headers();
|
||||
|
||||
|
@ -1574,7 +1668,7 @@ class WC_AJAX {
|
|||
|
||||
$menu_order = 0;
|
||||
|
||||
foreach( $siblings as $sibling ) {
|
||||
foreach ( $siblings as $sibling ) {
|
||||
|
||||
// if this is the post that comes after our repositioned post, set our repositioned post position and increment menu order
|
||||
if ( $nextid == $sibling->ID ) {
|
||||
|
@ -1592,8 +1686,9 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
// if repositioned post has been set, and new items are already in the right order, we can stop
|
||||
if ( isset( $new_pos[ $post->ID ] ) && $sibling->menu_order >= $menu_order )
|
||||
if ( isset( $new_pos[ $post->ID ] ) && $sibling->menu_order >= $menu_order ) {
|
||||
break;
|
||||
}
|
||||
|
||||
// set the menu order of the current sibling and increment the menu order
|
||||
$wpdb->update(
|
||||
|
|
Loading…
Reference in New Issue