Show variable weights/dimensions even when parent values are not set.
This commit is contained in:
parent
4271617c79
commit
5a9dacd595
|
@ -1429,7 +1429,7 @@ class WC_Product {
|
|||
* @return bool
|
||||
*/
|
||||
public function enable_dimensions_display() {
|
||||
return apply_filters( 'wc_product_enable_dimensions_display', true );
|
||||
return apply_filters( 'wc_product_enable_dimensions_display', true ) && ( $this->has_dimensions() || $this->has_weight() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1441,6 +1441,15 @@ class WC_Product {
|
|||
return $this->get_dimensions() ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a child have dimensions set?
|
||||
* @since 2.7.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function child_has_dimensions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the product length.
|
||||
* @return string
|
||||
|
@ -1483,6 +1492,15 @@ class WC_Product {
|
|||
return $this->get_weight() ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a child have a weight set?
|
||||
* @since 2.7.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function child_has_weight() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatted dimensions.
|
||||
* @return string
|
||||
|
@ -1498,7 +1516,7 @@ class WC_Product {
|
|||
$dimensions .= ' ' . get_option( 'woocommerce_dimension_unit' );
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_product_dimensions', $dimensions, $this );
|
||||
return apply_filters( 'woocommerce_product_dimensions', $dimensions, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -610,7 +610,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
'price_html' => apply_filters( 'woocommerce_show_variation_price', $variation->get_price() === "" || $this->get_variation_price( 'min' ) !== $this->get_variation_price( 'max' ), $this, $variation ) ? '<span class="price">' . $variation->get_price_html() . '</span>' : '',
|
||||
'availability_html' => $availability_html,
|
||||
'sku' => $variation->get_sku(),
|
||||
'weight' => $variation->get_weight() . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) ),
|
||||
'weight' => $variation->get_weight() ? $variation->get_weight() . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) ) : '',
|
||||
'dimensions' => $variation->get_dimensions(),
|
||||
'min_qty' => 1,
|
||||
'max_qty' => $variation->backorders_allowed() ? '' : $variation->get_stock_quantity(),
|
||||
|
@ -723,6 +723,33 @@ class WC_Product_Variable extends WC_Product {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a child have a weight set?
|
||||
* @since 2.7.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function child_has_weight() {
|
||||
return boolval( get_post_meta( $this->id, '_child_has_weight', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a child have dimensions set?
|
||||
* @since 2.7.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function child_has_dimensions() {
|
||||
return boolval( get_post_meta( $this->id, '_child_has_dimensions', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not we are showing dimensions on the product page.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function enable_dimensions_display() {
|
||||
return apply_filters( 'wc_product_enable_dimensions_display', true ) && ( $this->has_dimensions() || $this->has_weight() || $this->child_has_weight() || $this->child_has_dimensions() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync the variable product with it's children.
|
||||
*/
|
||||
|
@ -740,6 +767,8 @@ class WC_Product_Variable extends WC_Product {
|
|||
// No published variations - product won't be purchasable.
|
||||
if ( ! $children ) {
|
||||
update_post_meta( $product_id, '_price', '' );
|
||||
delete_post_meta( $product_id, '_child_has_weight' );
|
||||
delete_post_meta( $product_id, '_child_has_dimensions' );
|
||||
delete_transient( 'wc_products_onsale' );
|
||||
|
||||
if ( is_admin() && 'publish' === get_post_status( $product_id ) ) {
|
||||
|
@ -826,6 +855,22 @@ class WC_Product_Variable extends WC_Product {
|
|||
add_post_meta( $product_id, '_price', $max_price, false );
|
||||
delete_transient( 'wc_products_onsale' );
|
||||
|
||||
// Sync weights
|
||||
foreach ( $children as $child_id ) {
|
||||
if ( get_post_meta( $child_id, '_weight', true ) ) {
|
||||
update_post_meta( $product_id, '_child_has_weight', true );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Sync dimensions
|
||||
foreach ( $children as $child_id ) {
|
||||
if ( get_post_meta( $child_id, '_height', true ) || get_post_meta( $child_id, '_width', true ) || get_post_meta( $child_id, '_length', true ) ) {
|
||||
update_post_meta( $product_id, '_child_has_dimensions', true );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Sync attributes
|
||||
self::sync_attributes( $product_id, $children );
|
||||
|
||||
|
|
|
@ -1141,7 +1141,7 @@ if ( ! function_exists( 'woocommerce_default_product_tabs' ) ) {
|
|||
}
|
||||
|
||||
// Additional information tab - shows attributes
|
||||
if ( $product && ( $product->has_attributes() || ( $product->enable_dimensions_display() && ( $product->has_dimensions() || $product->has_weight() ) ) ) ) {
|
||||
if ( $product && ( $product->has_attributes() || $product->enable_dimensions_display() ) ) {
|
||||
$tabs['additional_information'] = array(
|
||||
'title' => __( 'Additional Information', 'woocommerce' ),
|
||||
'priority' => 20,
|
||||
|
|
|
@ -165,6 +165,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Redirect to login after password reset.
|
||||
* When using authorizations in PayPal standard, automatically capture funds when the order goes processing/completed.
|
||||
* On multisite, when a user logs into a store with an account on a site, but not the current site, rather than error, add the user to the current site as a customer.
|
||||
* Show variable weights/dimensions even when parent values are not set.
|
||||
|
||||
[See changelog for all versions](https://raw.githubusercontent.com/woothemes/woocommerce/master/CHANGELOG.txt).
|
||||
|
||||
|
|
|
@ -33,17 +33,17 @@ ob_start();
|
|||
|
||||
<?php if ( $product->enable_dimensions_display() ) : ?>
|
||||
|
||||
<?php if ( $product->has_weight() ) : $has_row = true; ?>
|
||||
<?php if ( $product->has_weight() || get_post_meta( $product->id, '_child_has_weight', true ) ) : $has_row = true; ?>
|
||||
<tr class="<?php if ( ( $alt = $alt * -1 ) === 1 ) echo 'alt'; ?>">
|
||||
<th><?php _e( 'Weight', 'woocommerce' ) ?></th>
|
||||
<td class="product_weight"><?php echo wc_format_localized_decimal( $product->get_weight() ) . ' ' . esc_attr( get_option( 'woocommerce_weight_unit' ) ); ?></td>
|
||||
<td class="product_weight"><?php echo $product->get_weight() ? wc_format_localized_decimal( $product->get_weight() ) . ' ' . esc_attr( get_option( 'woocommerce_weight_unit' ) ) : __( 'N/A', 'woocommerce' ); ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $product->has_dimensions() ) : $has_row = true; ?>
|
||||
<?php if ( $product->has_dimensions() || get_post_meta( $product->id, '_child_has_dimensions', true ) ) : $has_row = true; ?>
|
||||
<tr class="<?php if ( ( $alt = $alt * -1 ) === 1 ) echo 'alt'; ?>">
|
||||
<th><?php _e( 'Dimensions', 'woocommerce' ) ?></th>
|
||||
<td class="product_dimensions"><?php echo $product->get_dimensions(); ?></td>
|
||||
<td class="product_dimensions"><?php echo $product->get_dimensions() ? $product->get_dimensions() : __( 'N/A', 'woocommerce' ); ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
Loading…
Reference in New Issue