ID;
$product_custom_fields = get_post_custom( $thepostid );
?>
';
// 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 '
';
// External URL
woocommerce_wp_text_input( array( 'id' => 'product_url', 'label' => __('Product URL', 'woothemes'), 'placeholder' => 'http://', 'description' => __('Enter the external URL to the product.', 'woothemes') ) );
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 '
';
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', 'wrapper_class' => 'show_if_simple show_if_variable', '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;
?>
';
// 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 '
';
?>
get_var($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE meta_key='sku' AND meta_value='%s';", $new_sku)) ||
$wpdb->get_var($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID='%s' AND ID!='%s' AND post_type='product';", $new_sku, $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
);
endif;
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 + Downloadable/Virtual
$product_type = sanitize_title( stripslashes( $_POST['product-type'] ) );
$is_downloadable = (isset($_POST['downloadable'])) ? 'yes' : 'no';
$is_virtual = (isset($_POST['virtual'])) ? 'yes' : 'no';
if( !$product_type ) $product_type = 'simple';
wp_set_object_terms($post_id, $product_type, 'product_type');
update_post_meta( $post_id, 'downloadable', $is_downloadable );
update_post_meta( $post_id, 'virtual', $is_virtual );
// Set transient for product type
set_transient( 'woocommerce_product_type_' . $post_id, $product_type );
// Sales and prices
if ($product_type=='simple' || $product_type=='external') :
$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;
// Clear cache/transients
$woocommerce->clear_product_transients( $post_parent );
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;
elseif ($product_type!=='external') :
update_post_meta( $post_id, 'stock', '0' );
update_post_meta( $post_id, 'manage_stock', 'no' );
update_post_meta( $post_id, 'backorders', 'no' );
else :
update_post_meta( $post_id, 'stock_status', 'instock' );
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 );
else :
delete_post_meta( $post_id, 'upsell_ids' );
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 );
else :
delete_post_meta( $post_id, 'crosssell_ids' );
endif;
// Downloadable options
if ($is_downloadable=='yes') :
if (isset($_POST['file_path']) && $_POST['file_path']) update_post_meta( $post_id, 'file_path', esc_attr($_POST['file_path']) );
if (isset($_POST['download_limit'])) update_post_meta( $post_id, 'download_limit', esc_attr($_POST['download_limit']) );
endif;
// Product url
if ($product_type=='external') :
if (isset($_POST['product_url']) && $_POST['product_url']) update_post_meta( $post_id, 'product_url', esc_attr($_POST['product_url']) );
endif;
// Do action for product type
do_action( 'woocommerce_process_product_meta_' . $product_type, $post_id );
// Clear cache/transients
$woocommerce->clear_product_transients( $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);
?>× 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 product', 'woothemes'),
'grouped' => __('Grouped product', 'woothemes'),
'external' => __('External/Affiliate product', 'woothemes')
), $product_type) ) );
// Visibility
woocommerce_wp_select( array( 'id' => 'visibility', 'label' => __('Product visibility', 'woothemes'), 'options' => array(
'visible' => __('Catalog & Search', 'woothemes'),
'catalog' => __('Catalog', 'woothemes'),
'search' => __('Search', 'woothemes'),
'hidden' => __('Hidden', 'woothemes')
) ) );
woocommerce_wp_checkbox( array( 'id' => 'virtual', 'wrapper_class' => 'show_if_simple', 'label' => __('Virtual', 'woothemes'), 'description' => __('Enable this option if a product is not shipped or there is no shipping cost', 'woothemes') ) );
woocommerce_wp_checkbox( array( 'id' => 'downloadable', 'wrapper_class' => 'show_if_simple', 'label' => __('Downloadable', 'woothemes'), 'description' => __('Enable this option if access is given to a downloadable file upon purchase of a product', 'woothemes') ) );
// Featured
woocommerce_wp_checkbox( array( 'id' => 'featured', 'label' => __('Featured', 'woothemes'), 'description' => __('Enable this option to feature this product', 'woothemes') ) );
echo '
';
}
/**
* Change label for insert buttons
*/
add_filter( 'gettext', 'woocommerce_change_insert_into_post', null, 2 );
function woocommerce_change_insert_into_post( $translation, $original ) {
if( !isset( $_REQUEST['from'] ) ) return $translation;
if( $_REQUEST['from'] == 'wc01' && $original == 'Insert into Post' ) return __('Insert into URL field', 'woothemes' );
return $translation;
}