Shipping classes for variations. Closes #553.
This commit is contained in:
parent
31ae4beed3
commit
a562132458
|
@ -73,6 +73,9 @@ function variable_product_type_options() {
|
|||
endif;
|
||||
|
||||
if (!$image) $image = $woocommerce->plugin_url().'/assets/images/placeholder.png';
|
||||
|
||||
$classes = get_the_terms( $variation->ID, 'product_shipping_class' );
|
||||
if ($classes && !is_wp_error($classes)) $current_shipping_class = current($classes)->term_id; else $current_shipping_class = '';
|
||||
?>
|
||||
<div class="woocommerce_variation">
|
||||
<p>
|
||||
|
@ -133,6 +136,18 @@ function variable_product_type_options() {
|
|||
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
<td><label><?php _e('Shipping class:', 'woocommerce'); ?></label> <?php
|
||||
$args = array(
|
||||
'taxonomy' => 'product_shipping_class',
|
||||
'hide_empty' => 0,
|
||||
'show_option_all' => __('Same as parent', 'woocommerce'),
|
||||
'name' => 'variable_shipping_class['.$loop.']',
|
||||
'id' => '',
|
||||
'selected' => $current_shipping_class
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?></td>
|
||||
|
||||
<td><label><?php _e('Downloadable', 'woocommerce'); ?> <a class="tips" tip="<?php _e('Enable this option if access is given to a downloadable file upon purchase of a product.', 'woocommerce'); ?>" href="#">[?]</a></label><input type="checkbox" class="checkbox variable_is_downloadable" name="variable_is_downloadable[<?php echo $loop; ?>]" <?php if (isset($variation_data['_downloadable'][0])) checked($variation_data['_downloadable'][0], 'yes'); ?> /></td>
|
||||
|
||||
|
@ -151,8 +166,6 @@ function variable_product_type_options() {
|
|||
<label><?php _e('Download Limit:', 'woocommerce'); ?> <a class="tips" 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($variation_data['_download_limit'][0])) echo $variation_data['_download_limit'][0]; ?>" placeholder="<?php _e('Unlimited', 'woocommerce'); ?>" />
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td> </td>
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -293,6 +306,17 @@ function variable_product_type_options() {
|
|||
<td><label><?php _e('Sale Price:', 'woocommerce'); ?></label><input type="text" size="5" name="variable_sale_price[' + loop + ']" /></td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td><label><?php _e('Shipping class:', 'woocommerce'); ?></label> <?php
|
||||
$args = array(
|
||||
'taxonomy' => 'product_shipping_class',
|
||||
'hide_empty' => 0,
|
||||
'show_option_all' => __('Same as parent', 'woocommerce'),
|
||||
'name' => "variable_shipping_class[]",
|
||||
'id' => '',
|
||||
'echo' => 0
|
||||
);
|
||||
echo addslashes(str_replace('[]', "[' + loop + ']", str_replace("\n", '', wp_dropdown_categories( $args ))));
|
||||
?></td>\
|
||||
<td><label><?php _e('Downloadable', 'woocommerce'); ?> <a class="tips" tip="<?php _e('Enable this option if access is given to a downloadable file upon purchase of a product.', 'woocommerce'); ?>" href="#">[?]</a></label><input type="checkbox" class="checkbox variable_is_downloadable" name="variable_is_downloadable[' + loop + ']" /></td>\
|
||||
\
|
||||
<td><label><?php _e('Virtual', 'woocommerce'); ?> <a class="tips" tip="<?php _e('Enable this option if a product is not shipped or there is no shipping cost.', 'woocommerce'); ?>" href="#">[?]</a></label><input type="checkbox" class="checkbox" name="variable_is_virtual[' + loop + ']" /></td>\
|
||||
|
@ -306,7 +330,6 @@ function variable_product_type_options() {
|
|||
<td>\
|
||||
<div class="show_if_variation_downloadable" style="display:none;"><label><?php _e('Download Limit:', 'woocommerce'); ?> <a class="tips" tip="<?php _e('Leave blank for unlimited re-downloads.', 'woocommerce'); ?>" href="#">[?]</a></label><input type="text" size="5" name="variable_download_limit[' + loop + ']" placeholder="<?php _e('Unlimited', 'woocommerce'); ?>" /></div>\
|
||||
</td>\
|
||||
<td> </td>\
|
||||
</tr>\
|
||||
</tbody>\
|
||||
</table>\
|
||||
|
@ -582,6 +605,7 @@ function process_product_meta_variable( $post_id ) {
|
|||
if (isset($_POST['variable_is_downloadable'])) $variable_is_downloadable = $_POST['variable_is_downloadable'];
|
||||
$variable_file_path = $_POST['variable_file_path'];
|
||||
$variable_download_limit = $_POST['variable_download_limit'];
|
||||
$variable_shipping_class = $_POST['variable_shipping_class'];
|
||||
|
||||
$attributes = (array) maybe_unserialize( get_post_meta($post_id, '_product_attributes', true) );
|
||||
|
||||
|
@ -655,6 +679,10 @@ function process_product_meta_variable( $post_id ) {
|
|||
update_post_meta( $variation_id, '_file_path', '' );
|
||||
endif;
|
||||
|
||||
// Save shipping class
|
||||
$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;");
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ table.woocommerce_attributes,table.woocommerce_variable_attributes{width:100%;po
|
|||
table.woocommerce_attributes thead th,table.woocommerce_variable_attributes thead th{background:#ececec;padding:7px 9px;font-size:11px;text-align:left;}
|
||||
table.woocommerce_attributes td,table.woocommerce_variable_attributes td{padding:2px 9px;text-align:left;vertical-align:middle;border-bottom:1px dotted #ececec;}
|
||||
table.woocommerce_attributes td input,table.woocommerce_attributes td textarea,table.woocommerce_variable_attributes td input,table.woocommerce_variable_attributes td textarea{width:100%;margin:0;display:block;}
|
||||
table.woocommerce_attributes td select{width:100%;}
|
||||
table.woocommerce_attributes td select,table.woocommerce_variable_attributes td select{width:100%;}
|
||||
table.woocommerce_attributes td input,table.woocommerce_variable_attributes td input,table.woocommerce_variable_attributes td textarea{font-size:14px;padding:4px;color:#555;}
|
||||
table.woocommerce_attributes .taxonomy td.name{padding:10px 15px;font-size:14px;color:#555;}
|
||||
table.woocommerce_attributes .taxonomy td.values{position:relative;}table.woocommerce_attributes .taxonomy td.values .chzn-container{width:100% !important;margin:0 1px;display:block;}table.woocommerce_attributes .taxonomy td.values .chzn-container .chzn-drop{width:100% !important;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;}
|
||||
|
|
|
@ -1151,7 +1151,7 @@ table.woocommerce_attributes td input, table.woocommerce_attributes td textarea,
|
|||
margin: 0;
|
||||
display: block;
|
||||
}
|
||||
table.woocommerce_attributes td select {
|
||||
table.woocommerce_attributes td select, table.woocommerce_variable_attributes td select {
|
||||
width: 100%;
|
||||
}
|
||||
table.woocommerce_attributes td input, table.woocommerce_variable_attributes td input, table.woocommerce_variable_attributes td textarea {
|
||||
|
|
|
@ -21,6 +21,7 @@ class WC_Product_Variation extends WC_Product {
|
|||
var $variation_has_sale_price;
|
||||
var $variation_has_stock;
|
||||
var $variation_has_sku;
|
||||
var $variation_shipping_class;
|
||||
|
||||
/**
|
||||
* Loads all product data from custom fields
|
||||
|
@ -260,6 +261,17 @@ class WC_Product_Variation extends WC_Product {
|
|||
return parent::increase_stock( $by );
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shipping class, and if not set, get the shipping class of the parent
|
||||
*/
|
||||
function get_shipping_class() {
|
||||
if (!$this->variation_shipping_class) :
|
||||
$classes = get_the_terms( $this->id, 'product_shipping_class' );
|
||||
if ($classes && !is_wp_error($classes)) $this->variation_shipping_class = current($classes)->slug; else $this->variation_shipping_class = parent::get_shipping_class();
|
||||
endif;
|
||||
return $this->variation_shipping_class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -658,7 +658,7 @@ class WC_Product {
|
|||
function get_shipping_class() {
|
||||
if (!$this->shipping_class) :
|
||||
$classes = get_the_terms( $this->id, 'product_shipping_class' );
|
||||
$this->shipping_class = (isset($classes[0])) ? $classes[0]->slug : '';
|
||||
if ($classes && !is_wp_error($classes)) $this->shipping_class = current($classes)->slug; else $this->shipping_class = '';
|
||||
endif;
|
||||
return $this->shipping_class;
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
|
|||
* Added sharedaddy support
|
||||
* Option to require login to download files
|
||||
* Option to display layered nav as a dropdown
|
||||
* Shipping classes added to individual product variations
|
||||
* woocommerce_nocache function for cart/checkout/myaccount pages which need to be dynamic
|
||||
* Other minor fixes
|
||||
|
||||
|
|
|
@ -537,7 +537,7 @@ class Woocommerce {
|
|||
);
|
||||
|
||||
register_taxonomy( 'product_shipping_class',
|
||||
array('product'),
|
||||
array('product', 'product_variation'),
|
||||
array(
|
||||
'hierarchical' => true,
|
||||
'update_count_callback' => '_update_post_term_count',
|
||||
|
|
Loading…
Reference in New Issue