ID;
$product_custom_fields = get_post_custom( $thepostid );
?>
';
// List Grouped products
$post_parents = array();
$post_parents[''] = __('Choose a grouped product…', 'woothemes');
$posts_in = array_unique((array) get_objects_in_term( get_term_by( 'slug', 'grouped', 'product_type' )->term_id, 'product_type' ));
if (sizeof($posts_in)>0) :
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'numberposts' => -1,
'orderby' => 'title',
'order' => 'asc',
'post_parent' => 0,
'include' => $posts_in,
);
$grouped_products = get_posts($args);
$loop = 0;
if ($grouped_products) : foreach ($grouped_products as $product) :
if ($product->ID==$post->ID) continue;
$post_parents[$product->ID] = $product->post_title;
endforeach; endif;
endif;
woocommerce_wp_select( array( 'id' => 'parent_id', 'label' => __('Grouping', 'woothemes'), 'value' => $post->post_parent, 'options' => $post_parents ) );
// Ordering
woocommerce_wp_text_input( array( 'id' => 'menu_order', 'label' => _x('Sort Order', 'ordering', 'woothemes'), 'value' => $post->menu_order ) );
do_action('woocommerce_product_options_grouping');
echo '
';
echo '
';
// SKU
if( get_option('woocommerce_enable_sku', true) !== 'no' ) :
woocommerce_wp_text_input( array( 'id' => 'sku', 'label' => __('SKU', 'woothemes'), 'placeholder' => $post->ID ) );
else:
echo ' ';
endif;
do_action('woocommerce_product_options_sku');
echo '
';
echo '
';
// Price
woocommerce_wp_text_input( array( 'id' => 'regular_price', 'label' => __('Regular Price', 'woothemes') . ' ('.get_woocommerce_currency_symbol().'):' ) );
// Special Price
woocommerce_wp_text_input( array( 'id' => 'sale_price', 'label' => __('Sale Price', 'woothemes') . ' ('.get_woocommerce_currency_symbol().'):' ) );
// Special Price date range
$field = array( 'id' => 'sale_price_dates', 'label' => __('Sale Price Dates', 'woothemes') );
$sale_price_dates_from = get_post_meta($thepostid, 'sale_price_dates_from', true);
$sale_price_dates_to = get_post_meta($thepostid, 'sale_price_dates_to', true);
echo '
'.$field['label'].':
' . __('Date format', 'woothemes') . ': YYYY-MM-DD
';
do_action('woocommerce_product_options_pricing');
echo '
';
echo '
';
// Weight
if( get_option('woocommerce_enable_weight', true) !== 'no' ) :
woocommerce_wp_text_input( array( 'id' => 'weight', 'label' => __('Weight', 'woothemes') . ' ('.get_option('woocommerce_weight_unit').')', 'placeholder' => '0.00' ) );
else:
echo ' ';
endif;
do_action('woocommerce_product_options_weight');
echo '
';
do_action('woocommerce_product_options_general_product_data');
?>
'tax_status', 'label' => __('Tax Status', 'woothemes'), 'options' => array(
'taxable' => __('Taxable', 'woothemes'),
'shipping' => __('Shipping only', 'woothemes'),
'none' => __('None', 'woothemes')
) ) );
$_tax = new woocommerce_tax();
$tax_classes = $_tax->get_tax_classes();
$classes_options = array();
$classes_options[''] = __('Standard', 'woothemes');
if ($tax_classes) foreach ($tax_classes as $class) :
$classes_options[sanitize_title($class)] = $class;
endforeach;
woocommerce_wp_select( array( 'id' => 'tax_class', 'label' => __('Tax Class', 'woothemes'), 'options' => $classes_options ) );
do_action('woocommerce_product_options_tax');
?>
'manage_stock', 'label' => __('Manage stock?', 'woothemes') ) );
// Stock status
woocommerce_wp_select( array( 'id' => 'stock_status', 'label' => __('Stock status', 'woothemes'), 'options' => array(
'instock' => __('In stock', 'woothemes'),
'outofstock' => __('Out of stock', 'woothemes')
) ) );
do_action('woocommerce_product_options_stock');
echo '
';
// Stock
woocommerce_wp_text_input( array( 'id' => 'stock', 'label' => __('Stock Qty', 'woothemes') ) );
// Backorders?
woocommerce_wp_select( array( 'id' => 'backorders', 'label' => __('Allow Backorders?', 'woothemes'), 'options' => array(
'no' => __('Do not allow', 'woothemes'),
'notify' => __('Allow, but notify customer', 'woothemes'),
'yes' => __('Allow', 'woothemes')
) ) );
do_action('woocommerce_product_options_stock_fields');
echo '
';
?>
attribute_taxonomy_name($tax->attribute_name);
$label = ($tax->attribute_label) ? $tax->attribute_label : $tax->attribute_name;
echo ''.$label.' ';
endforeach;
endif;
?>
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.";")) :
$woocommerce_errors[] = __('Product SKU must be unique.', 'woothemes');
else :
update_post_meta( $post_id, 'sku', $new_sku );
endif;
else :
update_post_meta( $post_id, 'sku', '' );
endif;
endif;
// Save Attributes
$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 htmlspecialchars(stripslashes($attribute_names[$i])),
'value' => '',
'position' => $attribute_position[$i],
'is_visible' => $is_visible,
'is_variation' => $is_variation,
'is_taxonomy' => $is_taxonomy
);
else :
// Format values
$values = htmlspecialchars(stripslashes($attribute_values[$i]));
// Text based, separate by pipe
$values = explode('|', $values);
$values = array_map('trim', $values);
$values = implode('|', $values);
// Custom attribute - Add attribute to array and set the values
$attributes[ sanitize_title( $attribute_names[$i] ) ] = array(
'name' => htmlspecialchars(stripslashes($attribute_names[$i])),
'value' => $values,
'position' => $attribute_position[$i],
'is_visible' => $is_visible,
'is_variation' => $is_variation,
'is_taxonomy' => $is_taxonomy
);
endif;
endfor;
endif;
if (!function_exists('attributes_cmp')) {
function attributes_cmp($a, $b) {
if ($a['position'] == $b['position']) {
return 0;
}
return ($a['position'] < $b['position']) ? -1 : 1;
}
}
uasort($attributes, 'attributes_cmp');
update_post_meta( $post_id, 'product_attributes', $attributes );
// Product type
$product_type = sanitize_title( stripslashes( $_POST['product-type'] ) );
if( !$product_type ) $product_type = 'simple';
wp_set_object_terms($post_id, $product_type, 'product_type');
// Sales and prices
if ($product_type!=='grouped' && $product_type!=='variable') :
$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 ($_POST['sale_price'] && $date_to == '' && $date_from == '') :
update_post_meta( $post_id, 'price', stripslashes($_POST['sale_price']) );
else :
update_post_meta( $post_id, 'price', stripslashes($_POST['regular_price']) );
endif;
if ($date_from && strtotime($date_from) < strtotime('NOW')) :
update_post_meta( $post_id, 'price', stripslashes($_POST['sale_price']) );
endif;
if ($date_to && strtotime($date_to) < strtotime('NOW')) :
update_post_meta( $post_id, 'price', stripslashes($_POST['regular_price']) );
update_post_meta( $post_id, 'sale_price_dates_from', '');
update_post_meta( $post_id, 'sale_price_dates_to', '');
endif;
else :
update_post_meta( $post_id, 'regular_price', '' );
update_post_meta( $post_id, 'sale_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;
// Update parent if grouped so price sorting works and stays in sync with the cheapest child
if ($post->post_parent>0 || $product_type=='grouped') :
$post_parent = ($post->post_parent>0) ? $post->post_parent : $post_id;
$children_by_price = get_posts( array(
'post_parent' => $post_parent,
'orderby' => 'meta_value_num',
'order' => 'asc',
'meta_key' => 'price',
'posts_per_page' => 1,
'post_type' => 'product',
'fields' => 'ids'
));
if ($children_by_price) :
foreach ($children_by_price as $child) :
$child_price = get_post_meta($child, 'price', true);
update_post_meta( $post_parent, 'price', $child_price );
endforeach;
endif;
endif;
// Stock Data
if (get_option('woocommerce_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'] );
update_post_meta( $post_id, 'manage_stock', 'yes' );
update_post_meta( $post_id, 'backorders', stripslashes( $_POST['backorders'] ) );
if ($product_type!=='variable' && $_POST['backorders']=='no' && $_POST['stock']<1) :
update_post_meta( $post_id, 'stock_status', 'outofstock' );
endif;
else :
update_post_meta( $post_id, 'stock', '0' );
update_post_meta( $post_id, 'manage_stock', 'no' );
update_post_meta( $post_id, 'backorders', 'no' );
endif;
endif;
// Upsells
if (isset($_POST['upsell_ids'])) :
$upsells = array();
$ids = $_POST['upsell_ids'];
foreach ($ids as $id) :
if ($id && $id>0) $upsells[] = $id;
endforeach;
update_post_meta( $post_id, 'upsell_ids', $upsells );
endif;
// Cross sells
if (isset($_POST['crosssell_ids'])) :
$crosssells = array();
$ids = $_POST['crosssell_ids'];
foreach ($ids as $id) :
if ($id && $id>0) $crosssells[] = $id;
endforeach;
update_post_meta( $post_id, 'crosssell_ids', $crosssells );
endif;
// Do action for product type
do_action( 'woocommerce_process_product_meta_' . $product_type, $post_id );
// Save errors
update_option('woocommerce_errors', $woocommerce_errors);
}
/**
* Outputs product list in selection boxes
**/
function woocommerce_product_selection_list_remove( $posts_to_display, $name ) {
global $thepostid;
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'numberposts' => -1,
'orderby' => 'title',
'order' => 'asc',
'include' => $posts_to_display,
);
$related_posts = get_posts($args);
$loop = 0;
if ($related_posts) : foreach ($related_posts as $related_post) :
if ($related_post->ID==$thepostid) continue;
$SKU = get_post_meta($related_post->ID, 'sku', true);
?>X post_title; ?> – #ID; ?> ID;
echo '';
// Product Type
if ($terms = wp_get_object_terms( $thepostid, 'product_type' )) $product_type = current($terms)->slug; else $product_type = 'simple';
woocommerce_wp_select( array( 'id' => 'product-type', 'label' => __('Product Type', 'woothemes'), 'value' => $product_type, 'options' => apply_filters('product_type_selector', array(
'simple' => __('Simple', 'woothemes')
), $product_type) ) );
// Visibility
woocommerce_wp_select( array( 'id' => 'visibility', 'label' => __('Visibility', 'woothemes'), 'options' => array(
'visible' => __('Catalog & Search', 'woothemes'),
'catalog' => __('Catalog', 'woothemes'),
'search' => __('Search', 'woothemes'),
'hidden' => __('Hidden', 'woothemes')
) ) );
// Featured
woocommerce_wp_checkbox( array( 'id' => 'featured', 'label' => __('Featured?', 'woothemes') ) );
echo '
';
}