WooCommerce custom product type not saving with namespaces
I am try to create my custom product type, but when I save it is still simple product. This because I am using namespacees but I can not figure out the problem.
This is class with new pt
namespace giftbox\models\woocommerce;
class WC_Product_Giftbox extends \WC_Product_Simple
{
protected $product_type = 'giftbox';
public function get_type()
{
return 'giftbox';
}
}
the name of the class I think is correct and I understood I don't need construct in WC 3.0
Then I have the class extend WC_Product_Giftbox
namespace giftbox\models\woocommerce;
class product_type extends WC_Product_Giftbox
{
/**
* Build the instance
*/
public function __construct()
{
add_filter('product_type_selector', array($this, 'add_type'));
register_activation_hook(__FILE__, array($this, 'install'));
add_filter('woocommerce_product_class', array($this, 'new_woocommerce_product_class'), 10, 2);
...
}
/**
* Giftbox Type
*
* @param array $types
* @return void
*/
public function add_type($types)
{
$types['giftbox'] = __('Gift Box', 'giftbox');
return $types;
}
public function install()
{
// If there is no giftbox product type taxonomy, add it.
if (!get_term_by('slug', 'giftbox', 'product_type')) {
wp_insert_term('giftbox', 'product_type');
}
}
public function new_woocommerce_product_class($classname, $product_type)
{
if ($product_type == 'giftbox') {
$classname = 'giftbox';
}
return $classname;
}
}
Then in controller I just call the class
new product_type();
The new product type is there and is possible to select it, but if I try to save or update continues to remain simple product.
I check it inside database and is missing my custom product type but I am not sure if have to be saved there or not.
Topic namespace woocommerce-offtopic Wordpress
Category Web