htmlspecialchars(stripslashes($attribute_names[$i])), 'value' => $attribute_values[$i], 'position' => $attribute_position[$i], 'visible' => $visible, 'is_taxonomy' => $is_taxonomy ); if ($is_taxonomy=='yes') : // Update post terms $tax = $attribute_names[$i]; $value = $attribute_values[$i]; if (taxonomy_exists('product_attribute_'.strtolower(sanitize_title($tax)))) : wp_set_object_terms( $post_id, $value, 'product_attribute_'.strtolower(sanitize_title($tax)) ); endif; endif; endfor; endif; function attributes_cmp($a, $b) { if ($a['position'] == $b['position']) { return 0; } return ($a['position'] < $b['position']) ? -1 : 1; } uasort($attributes, 'attributes_cmp'); // Special handling of certain fields $product_type = stripslashes( $_POST['product-type'] ); switch($product_type) : case "grouped" : case "configurable" : case "virtual" : case "downloadable" : wp_set_object_terms($post_id, $product_type, 'product_type'); break; default : // Simple wp_set_object_terms($post_id, 'simple', 'product_type'); break; endswitch; // visibility $visibility = stripslashes( $_POST['visibility'] ); update_post_meta( $post_id, 'visibility', $visibility ); // Featured $featured = stripslashes( $_POST['featured'] ); update_post_meta( $post_id, 'featured', $featured ); // Unique SKU $SKU = get_post_meta($post_id, 'SKU', true); $new_sku = stripslashes( $_POST['sku'] ); if ($new_sku!==$SKU) : if ($new_sku && !empty($new_sku)) : if ($wpdb->get_var("SELECT * FROM $wpdb->postmeta WHERE meta_key='SKU' AND meta_value='".$new_sku."';") || $wpdb->get_var("SELECT * FROM $wpdb->posts WHERE ID='".$new_sku."' AND ID!=".$post_id.";")) : $jigoshop_errors[] = __('Product SKU must be unique.', 'jigoshop'); else : update_post_meta( $post_id, 'SKU', $new_sku ); endif; else : update_post_meta( $post_id, 'SKU', '' ); endif; endif; // Sales and prices if ($product_type!=='grouped') : $date_from = (isset($_POST['sale_price_dates_from'])) ? $_POST['sale_price_dates_from'] : ''; $date_to = (isset($_POST['sale_price_dates_to'])) ? $_POST['sale_price_dates_to'] : ''; // Dates if ($date_from) : update_post_meta( $post_id, 'sale_price_dates_from', strtotime($date_from) ); else : update_post_meta( $post_id, 'sale_price_dates_from', '' ); endif; if ($date_to) : update_post_meta( $post_id, 'sale_price_dates_to', strtotime($date_to) ); else : update_post_meta( $post_id, 'sale_price_dates_to', '' ); endif; if ($date_to && !$date_from) : update_post_meta( $post_id, 'sale_price_dates_from', strtotime('NOW') ); endif; // Update price if on sale if ($data['sale_price'] && $date_to == '' && $date_from == '') : update_post_meta( $post_id, 'price', $data['sale_price'] ); else : update_post_meta( $post_id, 'price', $data['regular_price'] ); endif; if ($date_from && $date_from < strtotime('NOW')) : update_post_meta( $post_id, 'price', $data['sale_price'] ); endif; if ($date_to && $date_to > strtotime('NOW')) : update_post_meta( $post_id, 'price', $data['regular_price'] ); update_post_meta( $post_id, 'sale_price_dates_from', ''); update_post_meta( $post_id, 'sale_price_dates_to', ''); endif; else : $data['sale_price'] = ''; $data['regular_price'] = ''; update_post_meta( $post_id, 'sale_price_dates_from', '' ); update_post_meta( $post_id, 'sale_price_dates_to', '' ); update_post_meta( $post_id, 'price', '' ); endif; // Stock Data if (get_option('jigoshop_manage_stock')=='yes') : // Manage Stock Checkbox if ($product_type!=='grouped' && isset($_POST['manage_stock']) && $_POST['manage_stock']) : update_post_meta( $post_id, 'stock', $_POST['stock'] ); $data['manage_stock'] = 'yes'; $data['backorders'] = stripslashes( $_POST['backorders'] ); else : update_post_meta( $post_id, 'stock', '0' ); $data['manage_stock'] = 'no'; $data['backorders'] = 'no'; endif; endif; // Apply filters to data $data = apply_filters( 'process_product_meta', $data, $post_id ); // Apply filter to data for product type $data = apply_filters( 'process_product_meta_' . $product_type, $data, $post_id ); // Do action for product type do_action( 'process_product_meta_' . $product_type, $data, $post_id ); // Save update_post_meta( $post_id, 'product_attributes', $attributes ); update_post_meta( $post_id, 'product_data', $data ); update_option('jigoshop_errors', $jigoshop_errors); }