Вот мой текущий класс:
Код: Выделить всё
class WC_Product_Custom extends WC_Product {
/**
* Constructor for the product type to extend the object.
*
* @param int|WC_Product|object $product Product ID or object.
*/
public function __construct( $product = 0 ) {
parent::__construct( $product );
// Define your custom properties and their default values.
// These will be added to the protected $data array.
$this->data['lead_times'] = [];
}
/**
* Get the value of lead_times.
*
* @return array
*/
public function get_lead_time() {
return $this->product_lead_type($this->id);
}
/**
* Set the value of lead_times.
*
* @param array $value The values to set.
* - @param int min_delivery_days
* - @param int max_delivery_days
*/
public function set_lead_time( $value = null ) {
if (!$value) {
$value = $this->product_lead_type($this->id);
}
$this->set_prop( 'lead_times', $value );
}
private function product_lead_type($product_id = null) {
return [
'min_delivery_days' => 1,
'max_delivery_days' => 10
];
}
}
function register_custom_product_type( $classname, $product_type, $product_id ) {
if ( 'simple' === $product_type ) {
$classname = 'WC_Product_Custom';
}
return $classname;
}
add_filter( 'woocommerce_product_class', 'register_custom_product_type', 10, 3 );
Подробнее здесь: https://stackoverflow.com/questions/797 ... duct-types
Мобильная версия