Add 'parent' to the list of valid tax classes for product variations
Commit d9f9e74bd
added a check to `WC_Product::set_tax_class()` to only accept valid tax classes, but this created a bug for product variations as this type of product has an extra tax class called 'parent'.
This commit fixes this problem by adding a new method to `WC_Product` that returns a list of valid tax classes. `WC_Product_Variation` then override this method, returning another list including the tax class 'parent'.
Fixes #17024
This commit is contained in:
parent
d769ef24f2
commit
fa0e5569f8
|
@ -902,7 +902,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
public function set_tax_class( $class ) {
|
||||
$class = sanitize_title( $class );
|
||||
$class = 'standard' === $class ? '' : $class;
|
||||
$valid_classes = WC_Tax::get_tax_class_slugs();
|
||||
$valid_classes = $this->get_valid_tax_classes();
|
||||
|
||||
if ( ! in_array( $class, $valid_classes ) ) {
|
||||
$class = '';
|
||||
|
@ -911,6 +911,15 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
$this->set_prop( 'tax_class', $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of valid tax classes
|
||||
*
|
||||
* @return array valid tax classes
|
||||
*/
|
||||
protected function get_valid_tax_classes() {
|
||||
return WC_Tax::get_tax_class_slugs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if product manage stock.
|
||||
*
|
||||
|
|
|
@ -487,4 +487,16 @@ class WC_Product_Variation extends WC_Product_Simple {
|
|||
public function variation_is_visible() {
|
||||
return apply_filters( 'woocommerce_variation_is_visible', 'publish' === get_post_status( $this->get_id() ) && '' !== $this->get_price(), $this->get_id(), $this->get_parent_id(), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return valid tax classes. Adds 'parent' to the default list of valid tax classes.
|
||||
*
|
||||
* @return array valid tax classes
|
||||
*/
|
||||
protected function get_valid_tax_classes() {
|
||||
$valid_classes = WC_Tax::get_tax_class_slugs();
|
||||
$valid_classes[] = 'parent';
|
||||
|
||||
return $valid_classes;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue