I often want to extend a ClassicCommerce class Some_Class. However, this is sometimes made difficult to do because ClassicCommerce sometimes constructs objects of Some_Class by "$some_object = new Some_Class();". I will explain the difficulty using the method prepare_attributes() of class WC_Meta_Box_Product_Data as an example.
public static function prepare_attributes( $data = false ) {
...
$attribute = new WC_Product_Attribute();
...
}
I have extended the class WC_Product_Attribute:
class SV_Product_Attribute extends WC_Product_Attribute {
}
However, my extension will not be constructed since MC_Product_Attribute WC_Meta_Box_Product_Data::method prepare_attributes() calls "new WC_Product_Attribute()". An easy totally backward compatible solution would be:
public static function WC_Meta_Box_Product_Data::prepare_attributes( $data = false ) {
...
$classname = apply_filters( 'woocommerce_product_attribute_class', 'WC_Product_Attribute', $data );
$attribute = new $classname();
...
}
I often want to extend a ClassicCommerce class Some_Class. However, this is sometimes made difficult to do because ClassicCommerce sometimes constructs objects of Some_Class by "$some_object = new Some_Class();". I will explain the difficulty using the method prepare_attributes() of class WC_Meta_Box_Product_Data as an example.
I have extended the class WC_Product_Attribute:
However, my extension will not be constructed since MC_Product_Attribute WC_Meta_Box_Product_Data::method prepare_attributes() calls "new WC_Product_Attribute()". An easy totally backward compatible solution would be: