counts in for loops are slow
This commit is contained in:
parent
aba42b5fc0
commit
f24b34aaba
|
@ -114,7 +114,8 @@ function woocommerce_duplicate_post_taxonomies($id, $new_id, $post_type) {
|
|||
$taxonomies = get_object_taxonomies($post_type); //array("category", "post_tag");
|
||||
foreach ($taxonomies as $taxonomy) {
|
||||
$post_terms = wp_get_object_terms($id, $taxonomy);
|
||||
for ($i=0; $i<count($post_terms); $i++) {
|
||||
$post_terms_count = sizeof( $post_terms );
|
||||
for ($i=0; $i<$post_terms_count; $i++) {
|
||||
wp_set_object_terms($new_id, $post_terms[$i]->slug, $taxonomy, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -646,8 +646,9 @@ function woocommerce_process_shop_order_meta( $post_id, $post ) {
|
|||
$order_taxes_compound = isset($_POST['_order_taxes_compound']) ? $_POST['_order_taxes_compound'] : array();
|
||||
$order_taxes_cart = $_POST['_order_taxes_cart'];
|
||||
$order_taxes_shipping = $_POST['_order_taxes_shipping'];
|
||||
$order_taxes_label_count = sizeof( $order_taxes_label );
|
||||
|
||||
for ($i=0; $i<sizeof($order_taxes_label); $i++) :
|
||||
for ($i=0; $i<$order_taxes_label_count; $i++) :
|
||||
|
||||
// Add to array if the tax amount is set
|
||||
if (!$order_taxes_cart[$i] && !$order_taxes_shipping[$i]) continue;
|
||||
|
@ -673,59 +674,62 @@ function woocommerce_process_shop_order_meta( $post_id, $post ) {
|
|||
$order_items = array();
|
||||
|
||||
if (isset($_POST['item_id'])) :
|
||||
$item_id = $_POST['item_id'];
|
||||
$item_variation = $_POST['item_variation'];
|
||||
$item_name = $_POST['item_name'];
|
||||
$item_quantity = $_POST['item_quantity'];
|
||||
|
||||
$line_subtotal = $_POST['line_subtotal'];
|
||||
$line_subtotal_tax = $_POST['line_subtotal_tax'];
|
||||
|
||||
$line_total = $_POST['line_total'];
|
||||
$line_tax = $_POST['line_tax'];
|
||||
|
||||
$item_meta_names = (isset($_POST['meta_name'])) ? $_POST['meta_name'] : '';
|
||||
$item_meta_values = (isset($_POST['meta_value'])) ? $_POST['meta_value'] : '';
|
||||
|
||||
$item_tax_class = $_POST['item_tax_class'];
|
||||
|
||||
for ($i=0; $i<sizeof($item_id); $i++) :
|
||||
$item_id = $_POST['item_id'];
|
||||
$item_variation = $_POST['item_variation'];
|
||||
$item_name = $_POST['item_name'];
|
||||
$item_quantity = $_POST['item_quantity'];
|
||||
|
||||
$line_subtotal = $_POST['line_subtotal'];
|
||||
$line_subtotal_tax = $_POST['line_subtotal_tax'];
|
||||
|
||||
$line_total = $_POST['line_total'];
|
||||
$line_tax = $_POST['line_tax'];
|
||||
|
||||
$item_meta_names = (isset($_POST['meta_name'])) ? $_POST['meta_name'] : '';
|
||||
$item_meta_values = (isset($_POST['meta_value'])) ? $_POST['meta_value'] : '';
|
||||
|
||||
$item_tax_class = $_POST['item_tax_class'];
|
||||
|
||||
$item_id_count = sizeof( $item_id );
|
||||
|
||||
for ($i=0; $i<$item_id_count; $i++) :
|
||||
|
||||
if (!isset($item_id[$i]) || !$item_id[$i]) continue;
|
||||
if (!isset($item_name[$i])) continue;
|
||||
if (!isset($item_quantity[$i]) || $item_quantity[$i] < 1) continue;
|
||||
if (!isset($line_total[$i])) continue;
|
||||
if (!isset($line_tax[$i])) continue;
|
||||
|
||||
// Meta
|
||||
$item_meta = new order_item_meta();
|
||||
|
||||
if (isset($item_meta_names[$i]) && isset($item_meta_values[$i])) :
|
||||
$meta_names = $item_meta_names[$i];
|
||||
$meta_values = $item_meta_values[$i];
|
||||
$meta_names_count = sizeof( $meta_names );
|
||||
|
||||
if (!isset($item_id[$i]) || !$item_id[$i]) continue;
|
||||
if (!isset($item_name[$i])) continue;
|
||||
if (!isset($item_quantity[$i]) || $item_quantity[$i] < 1) continue;
|
||||
if (!isset($line_total[$i])) continue;
|
||||
if (!isset($line_tax[$i])) continue;
|
||||
|
||||
// Meta
|
||||
$item_meta = new order_item_meta();
|
||||
|
||||
if (isset($item_meta_names[$i]) && isset($item_meta_values[$i])) :
|
||||
$meta_names = $item_meta_names[$i];
|
||||
$meta_values = $item_meta_values[$i];
|
||||
|
||||
for ($ii=0; $ii<sizeof($meta_names); $ii++) :
|
||||
$meta_name = esc_attr( $meta_names[$ii] );
|
||||
$meta_value = esc_attr( $meta_values[$ii] );
|
||||
if ($meta_name && $meta_value) :
|
||||
$item_meta->add( $meta_name, $meta_value );
|
||||
endif;
|
||||
endfor;
|
||||
endif;
|
||||
|
||||
// Add to array
|
||||
$order_items[] = apply_filters('update_order_item', array(
|
||||
'id' => htmlspecialchars(stripslashes($item_id[$i])),
|
||||
'variation_id' => (int) $item_variation[$i],
|
||||
'name' => htmlspecialchars(stripslashes($item_name[$i])),
|
||||
'qty' => (int) $item_quantity[$i],
|
||||
'line_total' => rtrim(rtrim(number_format(woocommerce_clean($line_total[$i]), 4, '.', ''), '0'), '.'),
|
||||
'line_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_tax[$i]), 4, '.', ''), '0'), '.'),
|
||||
'line_subtotal' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal[$i]), 4, '.', ''), '0'), '.'),
|
||||
'line_subtotal_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal_tax[$i]), 4, '.', ''), '0'), '.'),
|
||||
'item_meta' => $item_meta->meta,
|
||||
'tax_class' => woocommerce_clean($item_tax_class[$i])
|
||||
));
|
||||
for ($ii=0; $ii<$meta_names_count; $ii++) :
|
||||
$meta_name = esc_attr( $meta_names[$ii] );
|
||||
$meta_value = esc_attr( $meta_values[$ii] );
|
||||
if ($meta_name && $meta_value) :
|
||||
$item_meta->add( $meta_name, $meta_value );
|
||||
endif;
|
||||
endfor;
|
||||
endif;
|
||||
|
||||
// Add to array
|
||||
$order_items[] = apply_filters('update_order_item', array(
|
||||
'id' => htmlspecialchars(stripslashes($item_id[$i])),
|
||||
'variation_id' => (int) $item_variation[$i],
|
||||
'name' => htmlspecialchars(stripslashes($item_name[$i])),
|
||||
'qty' => (int) $item_quantity[$i],
|
||||
'line_total' => rtrim(rtrim(number_format(woocommerce_clean($line_total[$i]), 4, '.', ''), '0'), '.'),
|
||||
'line_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_tax[$i]), 4, '.', ''), '0'), '.'),
|
||||
'line_subtotal' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal[$i]), 4, '.', ''), '0'), '.'),
|
||||
'line_subtotal_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal_tax[$i]), 4, '.', ''), '0'), '.'),
|
||||
'item_meta' => $item_meta->meta,
|
||||
'tax_class' => woocommerce_clean($item_tax_class[$i])
|
||||
));
|
||||
|
||||
endfor;
|
||||
endif;
|
||||
|
|
|
@ -257,8 +257,8 @@ function woocommerce_order_downloads_save( $post_id, $post ) {
|
|||
$order_key = get_post_meta($post->ID, '_order_key', true);
|
||||
$customer_email = get_post_meta($post->ID, '_billing_email', true);
|
||||
$customer_user = (int) get_post_meta($post->ID, '_customer_user', true);
|
||||
|
||||
for ($i=0; $i<sizeof($download_ids); $i++) :
|
||||
$download_ids_count = sizeof( $download_ids );
|
||||
for ($i=0; $i<$download_ids_count; $i++) :
|
||||
|
||||
$data = array(
|
||||
'user_id' => $customer_user,
|
||||
|
|
|
@ -751,7 +751,9 @@ function process_product_meta_variable( $post_id ) {
|
|||
|
||||
$attributes = (array) maybe_unserialize( get_post_meta($post_id, '_product_attributes', true) );
|
||||
|
||||
for ( $i=0; $i <= max( array_keys( $_POST['variable_post_id'] ) ); $i++ ) :
|
||||
$max_loop = max( array_keys( $_POST['variable_post_id'] ) );
|
||||
|
||||
for ( $i=0; $i <= $max_loop; $i++ ) :
|
||||
|
||||
if ( ! isset( $variable_post_id[$i] ) ) continue;
|
||||
|
||||
|
|
|
@ -575,24 +575,26 @@ function woocommerce_process_product_meta( $post_id, $post ) {
|
|||
$attributes = array();
|
||||
|
||||
if (isset($_POST['attribute_names'])) :
|
||||
$attribute_names = $_POST['attribute_names'];
|
||||
$attribute_values = $_POST['attribute_values'];
|
||||
if (isset($_POST['attribute_visibility'])) $attribute_visibility = $_POST['attribute_visibility'];
|
||||
if (isset($_POST['attribute_variation'])) $attribute_variation = $_POST['attribute_variation'];
|
||||
$attribute_is_taxonomy = $_POST['attribute_is_taxonomy'];
|
||||
$attribute_position = $_POST['attribute_position'];
|
||||
|
||||
for ($i=0; $i<sizeof($attribute_names); $i++) :
|
||||
if (!($attribute_names[$i])) continue;
|
||||
|
||||
$is_visible = (isset($attribute_visibility[$i])) ? 1 : 0;
|
||||
$is_variation = (isset($attribute_variation[$i])) ? 1 : 0;
|
||||
|
||||
$is_taxonomy = ($attribute_is_taxonomy[$i]) ? 1 : 0;
|
||||
|
||||
if ( $is_taxonomy ) {
|
||||
if ( isset( $attribute_values[$i] ) ) {
|
||||
|
||||
$attribute_names = $_POST['attribute_names'];
|
||||
$attribute_values = $_POST['attribute_values'];
|
||||
if (isset($_POST['attribute_visibility'])) $attribute_visibility = $_POST['attribute_visibility'];
|
||||
if (isset($_POST['attribute_variation'])) $attribute_variation = $_POST['attribute_variation'];
|
||||
$attribute_is_taxonomy = $_POST['attribute_is_taxonomy'];
|
||||
$attribute_position = $_POST['attribute_position'];
|
||||
|
||||
$attribute_names_count = sizeof( $attribute_names );
|
||||
|
||||
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;
|
||||
|
||||
$is_taxonomy = ($attribute_is_taxonomy[$i]) ? 1 : 0;
|
||||
|
||||
if ( $is_taxonomy ) {
|
||||
if ( isset( $attribute_values[$i] ) ) {
|
||||
|
||||
// Format values
|
||||
if ( is_array( $attribute_values[$i] ) ) {
|
||||
$values = array_map('htmlspecialchars', array_map('stripslashes', $attribute_values[$i]));
|
||||
|
@ -609,7 +611,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
|
|||
// Update post terms
|
||||
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
|
||||
$attributes[ sanitize_title( $attribute_names[$i] ) ] = array(
|
||||
|
|
|
@ -28,8 +28,8 @@ function woocommerce_update_options($options) {
|
|||
$tax_postcode = (isset($_POST['tax_postcode'])) ? $_POST['tax_postcode'] : array();
|
||||
$tax_compound = (isset($_POST['tax_compound'])) ? $_POST['tax_compound'] : array();
|
||||
$tax_label = (isset($_POST['tax_label'])) ? $_POST['tax_label'] : array();
|
||||
|
||||
for ($i=0; $i<sizeof($tax_classes); $i++) :
|
||||
$tax_classes_count = sizeof( $tax_classes );
|
||||
for ($i=0; $i<$tax_classes_count; $i++) :
|
||||
|
||||
if (isset($tax_classes[$i]) && isset($tax_countries[$i]) && isset($tax_rate[$i]) && is_numeric($tax_rate[$i])) :
|
||||
|
||||
|
@ -84,8 +84,8 @@ function woocommerce_update_options($options) {
|
|||
$tax_postcode = (isset($_POST['local_tax_postcode'])) ? $_POST['local_tax_postcode'] : array();
|
||||
$tax_compound = (isset($_POST['local_tax_compound'])) ? $_POST['local_tax_compound'] : array();
|
||||
$tax_label = (isset($_POST['local_tax_label'])) ? $_POST['local_tax_label'] : array();
|
||||
|
||||
for ($i=0; $i<sizeof($tax_classes); $i++) :
|
||||
$tax_classes_count = sizeof( $tax_classes );
|
||||
for ($i=0; $i<$tax_classes_count; $i++) :
|
||||
|
||||
if (isset($tax_classes[$i]) && isset($tax_countries[$i]) && isset($tax_rate[$i]) && is_numeric($tax_rate[$i])) :
|
||||
|
||||
|
|
Loading…
Reference in New Issue