This commit is contained in:
Mike Jolley 2012-10-15 20:25:48 +01:00
parent 5d15f30cea
commit 98530b3f6d
4 changed files with 317 additions and 322 deletions

View File

@ -3,9 +3,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?>
<div class="woocommerce_variation wc-metabox closed">
<h3>
<button type="button" class="remove_variation button" rel="<?php echo $variation_id; ?>"><?php _e( 'Remove', 'woocommerce' ); ?></button>
<button type="button" class="remove_variation button" rel="<?php echo esc_attr( $variation_id ); ?>"><?php _e( 'Remove', 'woocommerce' ); ?></button>
<div class="handlediv" title="<?php _e( 'Click to toggle', 'woocommerce' ); ?>"></div>
<strong>#<?php echo $variation_id; ?> &mdash; </strong>
<strong>#<?php echo esc_html( $variation_id ); ?> &mdash; </strong>
<?php
foreach ( $parent_data['attributes'] as $attribute ) {
@ -17,18 +17,18 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$variation_selected_value = isset( $variation_data[ 'attribute_' . sanitize_title( $attribute['name'] ) ][0] ) ? $variation_data[ 'attribute_' . sanitize_title( $attribute['name'] ) ][0] : '';
// Name will be something like attribute_pa_color
echo '<select name="attribute_' . sanitize_title( $attribute['name'] ) . '[' . $loop . ']"><option value="">' . __( 'Any', 'woocommerce' ) . ' ' . $woocommerce->attribute_label( $attribute['name'] ) . '&hellip;</option>';
echo '<select name="attribute_' . sanitize_title( $attribute['name'] ) . '[' . $loop . ']"><option value="">' . __( 'Any', 'woocommerce' ) . ' ' . esc_html( $woocommerce->attribute_label( $attribute['name'] ) ) . '&hellip;</option>';
// Get terms for attribute taxonomy or value if its a custom attribute
if ( $attribute['is_taxonomy'] ) {
$post_terms = wp_get_post_terms( $parent_data['id'], $attribute['name'] );
foreach ( $post_terms as $term ) {
echo '<option ' . selected( $variation_selected_value, $term->slug, false ) . ' value="' . $term->slug . '">' . apply_filters( 'woocommerce_variation_option_name', $term->name ) . '</option>';
echo '<option ' . selected( $variation_selected_value, $term->slug, false ) . ' value="' . esc_attr( $term->slug ) . '">' . apply_filters( 'woocommerce_variation_option_name', esc_html( $term->name ) ) . '</option>';
}
} else {
$options = explode( '|', $attribute['value'] );
foreach ( $options as $option ) {
echo '<option ' . selected( $variation_selected_value, $option, false ) . ' value="' . $option . '">' . ucfirst( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
echo '<option ' . selected( $variation_selected_value, $option, false ) . ' value="' . esc_attr( $option ) . '">' . ucfirst( apply_filters( 'woocommerce_variation_option_name', esc_html( $option ) ) ) . '</option>';
}
}
@ -44,9 +44,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<td class="sku" colspan="2">
<?php if ( get_option( 'woocommerce_enable_sku', true ) !== 'no' ) : ?>
<label><?php _e( 'SKU', 'woocommerce' ); ?>: <a class="tips" data-tip="<?php _e( 'Enter a SKU for this variation or leave blank to use the parent product SKU.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="text" size="5" name="variable_sku[<?php echo $loop; ?>]" value="<?php if ( isset( $_sku ) ) echo $_sku; ?>" placeholder="<?php echo $parent_data['sku']; ?>" />
<input type="text" size="5" name="variable_sku[<?php echo $loop; ?>]" value="<?php if ( isset( $_sku ) ) echo esc_attr( $_sku ); ?>" placeholder="<?php echo esc_attr( $parent_data['sku'] ); ?>" />
<?php else : ?>
<input type="hidden" name="variable_sku[<?php echo $loop; ?>]" value="<?php if ( isset( $_sku ) ) echo $_sku; ?>" />
<input type="hidden" name="variable_sku[<?php echo $loop; ?>]" value="<?php if ( isset( $_sku ) ) echo esc_attr( $_sku ); ?>" />
<?php endif; ?>
</td>
<td class="data" rowspan="2">
@ -55,7 +55,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<tr>
<td>
<label><?php _e( 'Stock Qty:', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e( 'Enter a quantity to enable stock management for this variation, or leave blank to use the variable product stock options.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="text" size="5" name="variable_stock[<?php echo $loop; ?>]" value="<?php if ( isset( $_stock ) ) echo $_stock; ?>" />
<input type="text" size="5" name="variable_stock[<?php echo $loop; ?>]" value="<?php if ( isset( $_stock ) ) echo esc_attr( $_stock ); ?>" />
</td>
<td>&nbsp;</td>
</tr>
@ -64,11 +64,11 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<tr>
<td>
<label><?php _e( 'Price:', 'woocommerce' ); ?></label>
<input type="text" size="5" name="variable_regular_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_regular_price ) ) echo $_regular_price; ?>" />
<input type="text" size="5" name="variable_regular_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_regular_price ) ) echo esc_attr( $_regular_price ); ?>" />
</td>
<td>
<label><?php _e( 'Sale Price:', 'woocommerce' ); ?> <a href="#" class="sale_schedule"><?php _e( 'Schedule', 'woocommerce' ); ?></a><a href="#" class="cancel_sale_schedule" style="display:none"><?php _e( 'Cancel schedule', 'woocommerce' ); ?></a></label>
<input type="text" size="5" name="variable_sale_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_sale_price ) ) echo $_sale_price; ?>" />
<input type="text" size="5" name="variable_sale_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_sale_price ) ) echo esc_attr( $_sale_price ); ?>" />
</td>
</tr>
@ -87,8 +87,8 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<tr>
<?php if ( get_option( 'woocommerce_enable_weight', true ) !== 'no' ) : ?>
<td class="hide_if_variation_virtual">
<label><?php _e( 'Weight', 'woocommerce' ) . ' (' . get_option( 'woocommerce_weight_unit' ) . '):'; ?> <a class="tips" data-tip="<?php _e( 'Enter a weight for this variation or leave blank to use the parent product weight.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="text" size="5" name="variable_weight[<?php echo $loop; ?>]" value="<?php if ( isset( $_weight ) ) echo $_weight; ?>" placeholder="<?php echo $parent_data['weight']; ?>" />
<label><?php _e( 'Weight', 'woocommerce' ) . ' (' . esc_html( get_option( 'woocommerce_weight_unit' ) ) . '):'; ?> <a class="tips" data-tip="<?php _e( 'Enter a weight for this variation or leave blank to use the parent product weight.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="text" size="5" name="variable_weight[<?php echo $loop; ?>]" value="<?php if ( isset( $_weight ) ) echo esc_attr( $_weight ); ?>" placeholder="<?php echo esc_attr( $parent_data['weight'] ); ?>" />
</td>
<?php else : ?>
<td>&nbsp;</td>
@ -96,9 +96,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<?php if ( get_option( 'woocommerce_enable_dimensions', true ) !== 'no' ) : ?>
<td class="dimensions_field hide_if_variation_virtual">
<label for"product_length"><?php echo __( 'Dimensions (L&times;W&times;H)', 'woocommerce' ); ?></label>
<input id="product_length" class="input-text" size="6" type="text" name="variable_length[<?php echo $loop; ?>]" value="<?php if ( isset( $_length ) ) echo $_length; ?>" placeholder="<?php echo $parent_data['length']; ?>" />
<input class="input-text" size="6" type="text" name="variable_width[<?php echo $loop; ?>]" value="<?php if ( isset( $_width ) ) echo $_width; ?>" placeholder="<?php echo $parent_data['width']; ?>" />
<input class="input-text last" size="6" type="text" name="variable_height[<?php echo $loop; ?>]" value="<?php if ( isset( $_height ) ) echo $_height; ?>" placeholder="<?php echo $parent_data['height']; ?>" />
<input id="product_length" class="input-text" size="6" type="text" name="variable_length[<?php echo $loop; ?>]" value="<?php if ( isset( $_length ) ) echo esc_attr( $_length ); ?>" placeholder="<?php echo esc_attr( $parent_data['length'] ); ?>" />
<input class="input-text" size="6" type="text" name="variable_width[<?php echo $loop; ?>]" value="<?php if ( isset( $_width ) ) echo esc_attr( $_width ); ?>" placeholder="<?php echo esc_attr( $parent_data['width'] ); ?>" />
<input class="input-text last" size="6" type="text" name="variable_height[<?php echo $loop; ?>]" value="<?php if ( isset( $_height ) ) echo esc_attr( $_height ); ?>" placeholder="<?php echo esc_attr( $parent_data['height'] ); ?>" />
</td>
<?php else : ?>
<td>&nbsp;</td>
@ -113,7 +113,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
'show_option_all' => __( 'Same as parent', 'woocommerce' ),
'name' => 'variable_shipping_class[' . $loop . ']',
'id' => '',
'selected' => isset( $shipping_class ) ? $shipping_class : '',
'selected' => isset( $shipping_class ) ? esc_attr( $shipping_class ) : '',
'echo' => 0
);
@ -123,7 +123,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<label><?php _e( 'Tax class:', 'woocommerce' ); ?></label>
<select name="variable_tax_class[<?php echo $loop; ?>]"><?php
foreach ( $parent_data['tax_class_options'] as $key => $value )
echo '<option value="' . $key . '" ' . selected( $key, $_tax_class, false ) . '>' . $value . '</option>';
echo '<option value="' . esc_attr( $key ) . '" ' . selected( $key, $_tax_class, false ) . '>' . esc_html( $value ) . '</option>';
?></select>
</td>
</tr>
@ -131,14 +131,14 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<td rowspan="2">
<div class="file_path_field">
<label><?php _e( 'File paths:', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e( 'Enter one or more File Paths, one per line, to make this variation a downloadable product, or leave blank.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<textarea style="float:left;" class="short file_paths" cols="20" rows="2" placeholder="<?php _e( 'File paths/URLs, one per line', 'woocommerce' ); ?>" name="variable_file_paths[<?php echo $loop; ?>]" wrap="off"><?php if ( isset( $_file_paths ) ) echo $_file_paths; ?></textarea>
<textarea style="float:left;" class="short file_paths" cols="20" rows="2" placeholder="<?php _e( 'File paths/URLs, one per line', 'woocommerce' ); ?>" name="variable_file_paths[<?php echo $loop; ?>]" wrap="off"><?php if ( isset( $_file_paths ) ) echo esc_textarea( $_file_paths ); ?></textarea>
<input type="button" class="upload_file_button button" value="<?php _e( 'Upload a file', 'woocommerce' ); ?>" title="<?php _e( 'Upload', 'woocommerce' ); ?>" />
</div>
</td>
<td>
<div>
<label><?php _e( 'Download Limit:', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e( 'Leave blank for unlimited re-downloads.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="text" size="5" name="variable_download_limit[<?php echo $loop; ?>]" value="<?php if ( isset( $_download_limit ) ) echo $_download_limit; ?>" placeholder="<?php _e( 'Unlimited', 'woocommerce' ); ?>" />
<input type="text" size="5" name="variable_download_limit[<?php echo $loop; ?>]" value="<?php if ( isset( $_download_limit ) ) echo esc_attr( $_download_limit ); ?>" placeholder="<?php _e( 'Unlimited', 'woocommerce' ); ?>" />
</div>
</td>
</tr>
@ -146,7 +146,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<td>
<div>
<label><?php _e( 'Download Expiry:', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e( 'Enter the number of days before a download link expires, or leave blank.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="text" size="5" name="variable_download_expiry[<?php echo $loop; ?>]" value="<?php if ( isset( $_download_expiry ) ) echo $_download_expiry; ?>" placeholder="<?php _e( 'Unlimited', 'woocommerce' ); ?>" />
<input type="text" size="5" name="variable_download_expiry[<?php echo $loop; ?>]" value="<?php if ( isset( $_download_expiry ) ) echo esc_attr( $_download_expiry ); ?>" placeholder="<?php _e( 'Unlimited', 'woocommerce' ); ?>" />
</div>
</td>
</tr>
@ -156,7 +156,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
</tr>
<tr>
<td class="upload_image">
<a href="#" class="upload_image_button <?php if ( $image_id > 0 ) echo 'remove'; ?>" rel="<?php echo $variation_id; ?>"><img src="<?php if ( ! empty( $image ) ) echo $image; else echo woocommerce_placeholder_img_src(); ?>" /><input type="hidden" name="upload_image_id[<?php echo $loop; ?>]" class="upload_image_id" value="<?php echo $image_id; ?>" /><span class="overlay"></span></a>
<a href="#" class="upload_image_button <?php if ( $image_id > 0 ) echo 'remove'; ?>" rel="<?php echo esc_attr( $variation_id ); ?>"><img src="<?php if ( ! empty( $image ) ) echo esc_attr( $image ); else echo esc_attr( woocommerce_placeholder_img_src() ); ?>" /><input type="hidden" name="upload_image_id[<?php echo $loop; ?>]" class="upload_image_id" value="<?php echo esc_attr( $image_id ); ?>" /><span class="overlay"></span></a>
</td>
<td class="options">
<label><input type="checkbox" class="checkbox" name="variable_enabled[<?php echo $loop; ?>]" <?php checked( $variation_post_status, 'publish' ); ?> /> <?php _e( 'Enabled', 'woocommerce' ); ?></label>

View File

@ -7,7 +7,7 @@
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/WritePanels
* @version 1.6.4
* @version 1.7.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@ -36,15 +36,15 @@ add_action('woocommerce_product_write_panel_tabs', 'variable_product_type_option
function variable_product_type_options() {
global $post, $woocommerce;
$attributes = (array) maybe_unserialize( get_post_meta($post->ID, '_product_attributes', true) );
$attributes = maybe_unserialize( get_post_meta( $post->ID, '_product_attributes', true ) );
// See if any are set
$variation_attribute_found = false;
if ( $attributes ) foreach( $attributes as $attribute ) {
if (isset($attribute['is_variation'])) :
if ( isset( $attribute['is_variation'] ) ) {
$variation_attribute_found = true;
break;
endif;
}
}
// Get tax classes
@ -52,9 +52,9 @@ function variable_product_type_options() {
$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 ) ] = esc_attr( $class );
?>
<div id="variable_product_options" class="panel wc-metaboxes-wrapper">
@ -129,8 +129,8 @@ function variable_product_type_options() {
$loop = 0;
if ( $variations ) foreach ( $variations as $variation ) {
$variation_id = $variation->ID;
$variation_post_status = $variation->post_status;
$variation_id = absint( $variation->ID );
$variation_post_status = esc_attr( $variation->post_status );
$variation_data = get_post_custom( $variation_id );
$variation_data['variation_post_id'] = $variation_id;
@ -167,8 +167,8 @@ function variable_product_type_options() {
$_regular_price = $_price;
// Get image
$image_id = absint( $_thumbnail_id );
$image = '';
$image_id = absint( $_thumbnail_id );
if ( $image_id )
$image = wp_get_attachment_url( $image_id );
@ -192,34 +192,32 @@ function variable_product_type_options() {
<strong><?php _e( 'Default selections:', 'woocommerce' ); ?></strong>
<?php
$default_attributes = (array) maybe_unserialize(get_post_meta( $post->ID, '_default_attributes', true ));
foreach ($attributes as $attribute) :
$default_attributes = maybe_unserialize( get_post_meta( $post->ID, '_default_attributes', true ) );
foreach ( $attributes as $attribute ) {
// Only deal with attributes that are variations
if ( !$attribute['is_variation'] ) continue;
if ( ! $attribute['is_variation'] )
continue;
// Get current value for variation (if set)
$variation_selected_value = (isset($default_attributes[sanitize_title($attribute['name'])])) ? $default_attributes[sanitize_title($attribute['name'])] : '';
$variation_selected_value = isset( $default_attributes[ sanitize_title( $attribute['name'] ) ] ) ? $default_attributes[ sanitize_title( $attribute['name'] ) ] : '';
// Name will be something like attribute_pa_color
echo '<select name="default_attribute_' . sanitize_title($attribute['name']).'"><option value="">'.__('No default', 'woocommerce') . ' ' . $woocommerce->attribute_label($attribute['name']).'&hellip;</option>';
echo '<select name="default_attribute_' . sanitize_title( $attribute['name'] ) . '"><option value="">' . __( 'No default', 'woocommerce' ) . ' ' . esc_html( $woocommerce->attribute_label( $attribute['name'] ) ) . '&hellip;</option>';
// Get terms for attribute taxonomy or value if its a custom attribute
if ($attribute['is_taxonomy']) :
if ( $attribute['is_taxonomy'] ) {
$post_terms = wp_get_post_terms( $post->ID, $attribute['name'] );
foreach ($post_terms as $term) :
echo '<option '.selected($variation_selected_value, $term->slug, false).' value="'.$term->slug.'">'.$term->name.'</option>';
endforeach;
else :
foreach ( $post_terms as $term )
echo '<option ' . selected( $variation_selected_value, $term->slug, false ) . ' value="' . esc_attr( $term->slug ) . '">' . esc_html( $term->name ) . '</option>';
} else {
$options = explode( '|', $attribute['value'] );
foreach ($options as $option) :
echo '<option '.selected($variation_selected_value, $option, false).' value="'.$option.'">'.ucfirst($option).'</option>';
endforeach;
endif;
foreach ( $options as $option )
echo '<option ' . selected( $variation_selected_value, $option, false ) . ' value="' . esc_attr( $option ) . '">' . ucfirst( esc_html( $option ) ) . '</option>';
}
echo '</select>';
endforeach;
}
?>
</p>
@ -590,19 +588,20 @@ function process_product_meta_variable( $post_id ) {
for ( $i = 0; $i <= $max_loop; $i ++ ) {
if ( ! isset( $variable_post_id[ $i ] ) ) continue;
if ( ! isset( $variable_post_id[ $i ] ) )
continue;
$variation_id = (int) $variable_post_id[ $i ];
$variation_id = absint( $variable_post_id[ $i ] );
// Virtal/Downloadable
if (isset($variable_is_virtual[ $i ])) $is_virtual = 'yes'; else $is_virtual = 'no';
if (isset($variable_is_downloadable[ $i ])) $is_downloadable = 'yes'; else $is_downloadable = 'no';
$is_virtual = isset( $variable_is_virtual[ $i ] ) ? 'yes' : 'no';
$is_downloadable = isset( $variable_is_downloadable[ $i ] ) ? 'yes' : 'no';
// Enabled or disabled
if (isset($variable_enabled[ $i ])) $post_status = 'publish'; else $post_status = 'private';
$post_status = isset( $variable_enabled[ $i ] ) ? 'publish' : 'private';
// Generate a useful post title
$variation_post_title = sprintf(__('Variation #%s of %s', 'woocommerce'), $variation_id, get_the_title($post_id));
$variation_post_title = sprintf( __( 'Variation #%s of %s', 'woocommerce' ), absint( $variation_id ), esc_html( get_the_title( $post_id ) ) );
// Update or Add post
if ( ! $variation_id ) {
@ -625,24 +624,24 @@ function process_product_meta_variable( $post_id ) {
}
// Update post meta
update_post_meta( $variation_id, '_sku', esc_html( $variable_sku[ $i ] ) );
update_post_meta( $variation_id, '_weight', $variable_weight[ $i ] );
update_post_meta( $variation_id, '_sku', esc_attr( $variable_sku[ $i ] ) );
update_post_meta( $variation_id, '_weight', esc_attr( $variable_weight[ $i ] ) );
update_post_meta( $variation_id, '_length', $variable_length[ $i ] );
update_post_meta( $variation_id, '_width', $variable_width[ $i ] );
update_post_meta( $variation_id, '_height', $variable_height[ $i ] );
update_post_meta( $variation_id, '_length', esc_attr( $variable_length[ $i ] ) );
update_post_meta( $variation_id, '_width', esc_attr( $variable_width[ $i ] ) );
update_post_meta( $variation_id, '_height', esc_attr( $variable_height[ $i ] ) );
update_post_meta( $variation_id, '_stock', $variable_stock[ $i ] );
update_post_meta( $variation_id, '_thumbnail_id', $upload_image_id[ $i ] );
update_post_meta( $variation_id, '_stock', esc_attr( $variable_stock[ $i ] ) );
update_post_meta( $variation_id, '_thumbnail_id', absint( $upload_image_id[ $i ] ) );
update_post_meta( $variation_id, '_virtual', $is_virtual );
update_post_meta( $variation_id, '_downloadable', $is_downloadable );
update_post_meta( $variation_id, '_virtual', esc_attr( $is_virtual ) );
update_post_meta( $variation_id, '_downloadable', esc_attr( $is_downloadable ) );
// Price handling
$regular_price = $variable_regular_price[ $i ];
$sale_price = $variable_sale_price[ $i ];
$date_from = $variable_sale_price_dates_from[ $i ];
$date_to = $variable_sale_price_dates_to[ $i ];
$regular_price = esc_attr( $variable_regular_price[ $i ] );
$sale_price = esc_attr( $variable_sale_price[ $i ] );
$date_from = esc_attr( $variable_sale_price_dates_from[ $i ] );
$date_to = esc_attr( $variable_sale_price_dates_to[ $i ] );
update_post_meta( $variation_id, '_regular_price', $regular_price );
update_post_meta( $variation_id, '_sale_price', $sale_price );
@ -677,13 +676,13 @@ function process_product_meta_variable( $post_id ) {
}
if ( $variable_tax_class[ $i ] !== 'parent' )
update_post_meta( $variation_id, '_tax_class', $variable_tax_class[ $i ] );
update_post_meta( $variation_id, '_tax_class', esc_attr( $variable_tax_class[ $i ] ) );
else
delete_post_meta( $variation_id, '_tax_class' );
if ( $is_downloadable == 'yes' ) {
update_post_meta( $variation_id, '_download_limit', $variable_download_limit[ $i ] );
update_post_meta( $variation_id, '_download_expiry', $variable_download_expiry[ $i ] );
update_post_meta( $variation_id, '_download_limit', esc_attr( $variable_download_limit[ $i ] ) );
update_post_meta( $variation_id, '_download_expiry', esc_attr( $variable_download_expiry[ $i ] ) );
$_file_paths = array();
$file_paths = str_replace( "\r\n", "\n", esc_attr( $variable_file_paths[ $i ] ) );
@ -711,8 +710,9 @@ function process_product_meta_variable( $post_id ) {
$variable_shipping_class[ $i ] = ( $variable_shipping_class[ $i ] ) ? (int) $variable_shipping_class[ $i ] : '';
wp_set_object_terms( $variation_id, $variable_shipping_class[ $i ], 'product_shipping_class');
// Remove old taxnomies attributes so data is kept up to date
if ($variation_id) $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'attribute_%' AND post_id = $variation_id;");
// Remove old taxonomies attributes so data is kept up to date
if ( $variation_id )
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE %s AND post_id = %d;", 'attribute_%', $variation_id ) );
// Update taxonomies
foreach ( $attributes as $attribute ) {
@ -722,7 +722,6 @@ function process_product_meta_variable( $post_id ) {
$value = esc_attr( trim( $_POST[ 'attribute_' . sanitize_title( $attribute['name'] ) ][ $i ] ) );
update_post_meta( $variation_id, 'attribute_' . sanitize_title( $attribute['name'] ), $value );
}
}
@ -783,17 +782,15 @@ function process_product_meta_variable( $post_id ) {
// Update default attribute options setting
$default_attributes = array();
foreach ($attributes as $attribute) :
if ( $attribute['is_variation'] ) :
foreach ( $attributes as $attribute ) {
if ( $attribute['is_variation'] ) {
$value = esc_attr( trim( $_POST[ 'default_attribute_' . sanitize_title( $attribute['name'] ) ] ) );
if ($value) :
if ( $value )
$default_attributes[ sanitize_title( $attribute['name'] ) ] = $value;
endif;
endif;
endforeach;
}
}
update_post_meta( $post_parent, '_default_attributes', $default_attributes );
}
add_action( 'woocommerce_process_product_meta_variable', 'process_product_meta_variable' );

View File

@ -314,29 +314,29 @@ function woocommerce_product_data_box() {
if ( ! taxonomy_exists( $attribute_taxonomy_name ) ) continue;
// Get product data values for current taxonomy - this contains ordering and visibility data
if ( isset( $attributes[$attribute_taxonomy_name] ) ) $attribute = $attributes[$attribute_taxonomy_name];
if ( isset( $attributes[ $attribute_taxonomy_name ] ) )
$attribute = $attributes[ $attribute_taxonomy_name ];
$position = ( isset( $attribute['position'] ) ) ? $attribute['position'] : 0;
$position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] );
// Get terms of this taxonomy associated with current product
$post_terms = wp_get_post_terms( $thepostid, $attribute_taxonomy_name );
// Any set?
$has_terms = ( is_wp_error( $post_terms ) || ! $post_terms || sizeof( $post_terms ) == 0 ) ? 0 : 1;
?>
<div class="woocommerce_attribute wc-metabox closed taxonomy <?php echo $attribute_taxonomy_name; ?>" rel="<?php echo $position; ?>" <?php if ( ! $has_terms ) echo 'style="display:none"'; ?>>
<h3>
<button type="button" class="remove_row button"><?php _e( 'Remove', 'woocommerce' ); ?></button>
<div class="handlediv" title="<?php _e( 'Click to toggle', 'woocommerce' ); ?>"></div>
<strong class="attribute_name"><?php echo apply_filters( 'woocommerce_attribute_label', ($tax->attribute_label) ? $tax->attribute_label : $tax->attribute_name, $tax->attribute_name ); ?></strong>
<strong class="attribute_name"><?php echo apply_filters( 'woocommerce_attribute_label', $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name, $tax->attribute_name ); ?></strong>
</h3>
<table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data wc-metabox-content">
<tbody>
<tr>
<td class="attribute_name">
<label><?php _e( 'Name', 'woocommerce' ); ?>:</label>
<strong><?php echo ($tax->attribute_label) ? $tax->attribute_label : $tax->attribute_name; ?></strong>
<strong><?php echo $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name; ?></strong>
<input type="hidden" name="attribute_names[<?php echo $i; ?>]" value="<?php echo esc_attr( $attribute_taxonomy_name ); ?>" />
<input type="hidden" name="attribute_position[<?php echo $i; ?>]" class="attribute_position" value="<?php echo esc_attr( $position ); ?>" />
@ -348,12 +348,12 @@ function woocommerce_product_data_box() {
<select multiple="multiple" data-placeholder="<?php _e( 'Select terms', 'woocommerce' ); ?>" class="multiselect attribute_values" name="attribute_values[<?php echo $i; ?>][]">
<?php
$all_terms = get_terms( $attribute_taxonomy_name, 'orderby=name&hide_empty=0' );
if ($all_terms) :
foreach ($all_terms as $term) :
$has_term = ( has_term( $term->slug, $attribute_taxonomy_name, $thepostid ) ) ? 1 : 0;
if ( $all_terms ) {
foreach ( $all_terms as $term ) {
$has_term = has_term( $term->slug, $attribute_taxonomy_name, $thepostid ) ? 1 : 0;
echo '<option value="' . $term->slug . '" ' . selected( $has_term, 1, false ) . '>' . $term->name . '</option>';
endforeach;
endif;
}
}
?>
</select>
@ -365,13 +365,12 @@ function woocommerce_product_data_box() {
<input type="text" name="attribute_values[<?php echo $i; ?>]" value="<?php
// Text attributes should list terms pipe separated
if ($post_terms) :
if ( $post_terms ) {
$values = array();
foreach ($post_terms as $term) :
foreach ( $post_terms as $term )
$values[] = $term->name;
endforeach;
echo implode( '|', $values );
endif;
}
?>" placeholder="<?php _e( 'Pipe separate terms', 'woocommerce' ); ?>" />
<?php endif; ?>
@ -379,13 +378,13 @@ function woocommerce_product_data_box() {
</tr>
<tr>
<td>
<label><input type="checkbox" class="checkbox" <?php if (isset($attribute['is_visible'])) checked($attribute['is_visible'], 1); ?> name="attribute_visibility[<?php echo $i; ?>]" value="1" /> <?php _e('Visible on the product page', 'woocommerce'); ?></label>
<label><input type="checkbox" class="checkbox" <?php checked( $attribute['is_visible'], 1 ); ?> name="attribute_visibility[<?php echo $i; ?>]" value="1" /> <?php _e( 'Visible on the product page', 'woocommerce' ); ?></label>
</td>
</tr>
<tr>
<td>
<div class="enable_variation show_if_variable">
<label><input type="checkbox" class="checkbox" <?php if (isset($attribute['is_variation'])) checked($attribute['is_variation'], 1); ?> name="attribute_variation[<?php echo $i; ?>]" value="1" /> <?php _e('Used for variations', 'woocommerce'); ?></label>
<label><input type="checkbox" class="checkbox" <?php checked( $attribute['is_variation'], 1 ); ?> name="attribute_variation[<?php echo $i; ?>]" value="1" /> <?php _e( 'Used for variations', 'woocommerce' ); ?></label>
</div>
</td>
</tr>
@ -397,19 +396,18 @@ function woocommerce_product_data_box() {
}
// Custom Attributes
if ($attributes && sizeof($attributes)>0) foreach ($attributes as $attribute) :
if ( ! empty( $attributes ) ) foreach ( $attributes as $attribute ) {
if ( $attribute['is_taxonomy'] ) continue;
$i++;
$position = (isset($attribute['position'])) ? $attribute['position'] : 0;
$position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] );
?>
<div class="woocommerce_attribute wc-metabox closed" rel="<?php echo $position; ?>">
<h3>
<button type="button" class="remove_row button"><?php _e( 'Remove', 'woocommerce' ); ?></button>
<div class="handlediv" title="<?php _e( 'Click to toggle', 'woocommerce' ); ?>"></div>
<strong class="attribute_name"><?php echo apply_filters( 'woocommerce_attribute_label', esc_attr( $attribute['name'] ), esc_attr( $attribute['name'] ) ); ?></strong>
<strong class="attribute_name"><?php echo apply_filters( 'woocommerce_attribute_label', esc_html( $attribute['name'] ), esc_html( $attribute['name'] ) ); ?></strong>
</h3>
<table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data wc-metabox-content">
<tbody>
@ -441,7 +439,7 @@ function woocommerce_product_data_box() {
</table>
</div>
<?php
endforeach;
}
?>
</div>
@ -450,17 +448,16 @@ function woocommerce_product_data_box() {
<select name="attribute_taxonomy" class="attribute_taxonomy">
<option value=""><?php _e( 'Custom product attribute', 'woocommerce' ); ?></option>
<?php
if ( $attribute_taxonomies ) :
foreach ($attribute_taxonomies as $tax) :
if ( $attribute_taxonomies ) {
foreach ( $attribute_taxonomies as $tax ) {
$attribute_taxonomy_name = $woocommerce->attribute_taxonomy_name( $tax->attribute_name );
$label = ($tax->attribute_label) ? $tax->attribute_label : $tax->attribute_name;
echo '<option value="'.$attribute_taxonomy_name.'">'.$label.'</option>';
endforeach;
endif;
$label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
echo '<option value="' . esc_attr( $attribute_taxonomy_name ) . '">' . esc_html( $label ) . '</option>';
}
}
?>
</select>
</p>
<div class="clear"></div>
</div>
<div id="related_product_data" class="panel woocommerce_options_panel">
@ -468,17 +465,19 @@ function woocommerce_product_data_box() {
<p class="form-field"><label for="upsell_ids"><?php _e( 'Up-Sells', 'woocommerce' ); ?></label>
<select id="upsell_ids" name="upsell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>">
<?php
$product_ids = get_post_meta( $post->ID, '_upsell_ids', true );
$product_ids = array_map( 'absint', get_post_meta( $post->ID, '_upsell_ids', true ) );
if ( $product_ids ) {
foreach ( $product_ids as $product_id ) {
$title = get_the_title( $product_id );
$sku = get_post_meta( $product_id, '_sku', true );
if (!$title) continue;
if ( ! $title )
continue;
if (isset($sku) && $sku) $sku = ' (SKU: ' . $sku . ')';
if ( ! empty( $sku ) )
$sku = ' (SKU: ' . $sku . ')';
echo '<option value="'.$product_id.'" selected="selected">'. $title . $sku .'</option>';
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
}
}
?>
@ -487,17 +486,19 @@ function woocommerce_product_data_box() {
<p class="form-field"><label for="crosssell_ids"><?php _e( 'Cross-Sells', 'woocommerce' ); ?></label>
<select id="crosssell_ids" name="crosssell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>">
<?php
$product_ids = get_post_meta( $post->ID, '_crosssell_ids', true );
$product_ids = array_map( 'absint', get_post_meta( $post->ID, '_crosssell_ids', true ) );
if ( $product_ids ) {
foreach ( $product_ids as $product_id ) {
$title = get_the_title( $product_id );
$sku = get_post_meta( $product_id, '_sku', true );
if (!$title) continue;
if ( ! $title )
continue;
if (isset($sku) && $sku) $sku = ' (SKU: ' . $sku . ')';
if ( ! empty( $sku ) )
$sku = ' (SKU: ' . $sku . ')';
echo '<option value="'.$product_id.'" selected="selected">'. $title . $sku .'</option>';
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
}
}
?>
@ -521,7 +522,7 @@ function woocommerce_product_data_box() {
echo '<div class="options_group">';
// menu_order
woocommerce_wp_text_input( array( 'id' => 'menu_order', 'label' => __('Menu order', 'woocommerce'), 'description' => __('Custom ordering position.', 'woocommerce'), 'value' => $post->menu_order ) );
woocommerce_wp_text_input( array( 'id' => 'menu_order', 'label' => __( 'Menu order', 'woocommerce' ), 'description' => __( 'Custom ordering position.', 'woocommerce' ), 'value' => intval( $post->menu_order ) ) );
echo '</div>';
@ -532,7 +533,7 @@ function woocommerce_product_data_box() {
$post_parents[''] = __( 'Choose a grouped product&hellip;', 'woocommerce' );
$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) :
if ( sizeof( $posts_in ) > 0 ) {
$args = array(
'post_type' => 'product',
'post_status' => 'any',
@ -543,17 +544,19 @@ function woocommerce_product_data_box() {
'include' => $posts_in,
);
$grouped_products = get_posts( $args );
$loop = 0;
if ($grouped_products) : foreach ($grouped_products as $product) :
if ($product->ID==$post->ID) continue;
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', 'woocommerce'), 'value' => $post->post_parent, 'options' => $post_parents ) );
woocommerce_wp_select( array( 'id' => 'parent_id', 'label' => __( 'Grouping', 'woocommerce' ), 'value' => absint( $post->post_parent ), 'options' => $post_parents ) );
do_action( 'woocommerce_product_options_grouping' );
@ -561,7 +564,7 @@ function woocommerce_product_data_box() {
echo '<div class="options_group reviews">';
woocommerce_wp_checkbox( array( 'id' => 'comment_status', 'label' => __('Enable reviews', 'woocommerce'), 'cbvalue' => 'open', 'value' => $post->comment_status ) );
woocommerce_wp_checkbox( array( 'id' => 'comment_status', 'label' => __( 'Enable reviews', 'woocommerce' ), 'cbvalue' => 'open', 'value' => esc_attr( $post->comment_status ) ) );
do_action( 'woocommerce_product_options_reviews' );
@ -955,11 +958,13 @@ add_action('woocommerce_process_product_meta', 'woocommerce_process_product_meta
* @return void
*/
function woocommerce_change_insert_into_post( $translation, $original ) {
if( !isset( $_REQUEST['from'] ) ) return $translation;
if ( ! isset( $_REQUEST['from'] ) )
return $translation;
$original = strtolower( $original );
if( $_REQUEST['from'] == 'wc01' && ($original == 'insert into post' || $original == 'use this image') ) return __('Use this file', 'woocommerce' );
if ( $_REQUEST['from'] == 'wc01' && ( $original == 'insert into post' || $original == 'use this image' ) )
return __( 'Use this file', 'woocommerce' );
return $translation;
}
@ -979,8 +984,8 @@ function woocommerce_product_data_visibility() {
if ( $post->post_type != 'product' )
return;
$current_visibility = get_post_meta( $post->ID, '_visibility', true );
$current_featured = get_post_meta( $post->ID, '_featured', true );
$current_visibility = ( $current_visibility = get_post_meta( $post->ID, '_visibility', true ) ) ? $current_visibility : 'visible';
$current_featured = ( $current_featured = get_post_meta( $post->ID, '_featured', true ) ) ? $current_featured : 'no';
$visibility_options = apply_filters( 'woocommerce_product_visibility_options', array(
'visible' => __( 'Catalog/search', 'woocommerce' ),
@ -988,12 +993,6 @@ function woocommerce_product_data_visibility() {
'search' => __( 'Search', 'woocommerce' ),
'hidden' => __( 'Hidden', 'woocommerce' )
) );
if ( ! $current_visibility )
$current_visibility = 'visible';
if ( ! $current_featured )
$current_featured = 'no';
?>
<div class="misc-pub-section" id="catalog-visibility">
<?php _e( 'Catalog visibility:', 'woocommerce' ); ?> <strong id="catalog-visibility-display"><?php
@ -1002,21 +1001,20 @@ function woocommerce_product_data_visibility() {
if ( $current_featured == 'yes' )
echo ', ' . __( 'Featured', 'woocommerce' );
?></strong>
<a href="#catalog-visibility" class="edit-catalog-visibility hide-if-no-js"><?php _e('Edit'); ?></a>
<a href="#catalog-visibility" class="edit-catalog-visibility hide-if-no-js"><?php _e( 'Edit', 'woocommerce' ); ?></a>
<div id="catalog-visibility-select" class="hide-if-js">
<input type="hidden" name="current_visibilty" id="current_visibilty" value="<?php echo $current_visibility; ?>" />
<input type="hidden" name="current_featured" id="current_featured" value="<?php echo $current_featured; ?>" />
<input type="hidden" name="current_visibilty" id="current_visibilty" value="<?php echo esc_attr( $current_visibility ); ?>" />
<input type="hidden" name="current_featured" id="current_featured" value="<?php echo esc_attr( $current_featured ); ?>" />
<?php
echo '<p>' . __( 'Define the loops this product should be visible in. The product will still be accessible directly.', 'woocommerce' ) . '</p>';
foreach ( $visibility_options as $name => $label ) {
echo '<input type="radio" name="_visibility" id="_visibility_' . $name . '" value="' . $name . '" ' . checked( $current_visibility, $name, false ). ' data-label="' . $label . '" /> <label for="_visibility_' . $name . '" class="selectit">' . $label . '</label><br />';
echo '<input type="radio" name="_visibility" id="_visibility_' . esc_attr( $name ) . '" value="' . esc_attr( $name ) . '" ' . checked( $current_visibility, $name, false ) . ' data-label="' . esc_attr( $label ) . '" /> <label for="_visibility_' . esc_attr( $name ) . '" class="selectit">' . esc_html( $label ) . '</label><br />';
}
echo '<p>' . __( 'Enable this option to feature this product.', 'woocommerce' ) . '</p>';
@ -1025,8 +1023,8 @@ function woocommerce_product_data_visibility() {
?>
<p>
<a href="#catalog-visibility" class="save-post-visibility hide-if-no-js button"><?php _e('OK'); ?></a>
<a href="#catalog-visibility" class="cancel-post-visibility hide-if-no-js"><?php _e('Cancel'); ?></a>
<a href="#catalog-visibility" class="save-post-visibility hide-if-no-js button"><?php _e( 'OK', 'woocommerce' ); ?></a>
<a href="#catalog-visibility" class="cancel-post-visibility hide-if-no-js"><?php _e( 'Cancel', 'woocommerce' ); ?></a>
</p>
</div>