Woocommerce(3.0)产品类型赢得';救不了

Woocommerce(3.0)产品类型赢得';救不了,woocommerce,Woocommerce,最近将Woocommerce更新为3.0,之后我无法保存我创建的自定义产品类型 这就是代码现在的样子 function register_xxxxxx_product_type() { class WC_Product_package extends WC_Product { public function __construct( $product ) { $this->product_type = 'xxxxxx'; parent::_

最近将Woocommerce更新为3.0,之后我无法保存我创建的自定义产品类型

这就是代码现在的样子

function register_xxxxxx_product_type() {

    class WC_Product_package extends WC_Product {
    public function __construct( $product ) {
        $this->product_type = 'xxxxxx';
        parent::__construct( $product );
    }
  }
}

add_action( 'plugins_loaded', 'register_xxxxxxx_product_type' );

function add_xxxxxx_package_product( $types ){
   // Key should be exactly the same as in the class
   $types[ 'xxxxxx' ] = __( 'xxxxxx' );
   $types[ 'xxxxxx' ] = __( 'xxxxxx' );
   $types[ 'xxxxxx' ] = __( 'xxxxxx' );
return $types;

}

add_filter( 'product_type_selector', 'add_xxxx_package_product' );
function register_daniel_product_type() {

class WC_Product_package extends WC_Product {

    public $product_type = 'daniel';
    public function __construct( $product ) {
        parent::__construct( $product );
    }
  }
}


add_action( 'init', 'register_daniel_product_type' );


function add_daniel_package_product( $types ){

// Key should be exactly the same as in the class

$types[ 'daniel_package' ] = __( 'Daniel Paket' );
$types[ 'daniel_parts' ] = __( 'Daniel Tillbehör' );
$types[ 'daniel_service' ] = __( 'Daniel Tillvalstjänster' );
return $types;
}

add_filter( 'product_type_selector', 'add_daniel_package_product' );

function woocommerce_product_class( $classname, $product_type ) {

if ( $product_type == 'daniel_package' ) { // notice the checking here.
    $classname = 'WC_Product_package';
}
return $classname;
}

add_filter( 'woocommerce_product_class', 'woocommerce_product_class', 10, 2 );
有人解决了这个问题吗

谢谢

更新

现在我的代码是这样的

function register_xxxxxx_product_type() {

class WC_Product_package extends WC_Product {

    public $product_type = 'NameOfType';
    public function __construct( $product ) {
        parent::__construct( $product );
    }
  }
}

 add_action( 'init', 'register_xxxxxx_product_type' );


  function add_xxxxxx_package_product( $types ){
 // Key should be exactly the same as in the class
 $types[ 'xxxxxx_package' ] = __( 'xxxxxx Paket' );
 $types[ 'xxxxxx_parts' ] = __( 'xxxxxx Tillbehör' );
 $types[ 'xxxxxx_service' ] = __( 'xxxxxx Tillvalstjänster' );
 return $types;

 }

 add_filter( 'product_type_selector', 'add_xxxxxx_package_product' );


 function woocommerce_product_class( $classname, $product_type ) {

 if ( $product_type == 'NameOfType' ) { // notice the checking here.
$classname = 'WC_Product_package';
 }

 return $classname;
 }

add_filter( 'woocommerce_product_class', 'woocommerce_product_class', 10, 2 );
但它不起作用。我做错了什么

更新#2

好的,这就是现在的样子

function register_xxxxxx_product_type() {

    class WC_Product_package extends WC_Product {
    public function __construct( $product ) {
        $this->product_type = 'xxxxxx';
        parent::__construct( $product );
    }
  }
}

add_action( 'plugins_loaded', 'register_xxxxxxx_product_type' );

function add_xxxxxx_package_product( $types ){
   // Key should be exactly the same as in the class
   $types[ 'xxxxxx' ] = __( 'xxxxxx' );
   $types[ 'xxxxxx' ] = __( 'xxxxxx' );
   $types[ 'xxxxxx' ] = __( 'xxxxxx' );
return $types;

}

add_filter( 'product_type_selector', 'add_xxxx_package_product' );
function register_daniel_product_type() {

class WC_Product_package extends WC_Product {

    public $product_type = 'daniel';
    public function __construct( $product ) {
        parent::__construct( $product );
    }
  }
}


add_action( 'init', 'register_daniel_product_type' );


function add_daniel_package_product( $types ){

// Key should be exactly the same as in the class

$types[ 'daniel_package' ] = __( 'Daniel Paket' );
$types[ 'daniel_parts' ] = __( 'Daniel Tillbehör' );
$types[ 'daniel_service' ] = __( 'Daniel Tillvalstjänster' );
return $types;
}

add_filter( 'product_type_selector', 'add_daniel_package_product' );

function woocommerce_product_class( $classname, $product_type ) {

if ( $product_type == 'daniel_package' ) { // notice the checking here.
    $classname = 'WC_Product_package';
}
return $classname;
}

add_filter( 'woocommerce_product_class', 'woocommerce_product_class', 10, 2 );
对不起,我说的太慢了,请你再给我一次机会解释一下

谢谢

这是怎么做的

首先确保扩展到
WC\u Product
的类已连接到
init

function register_xxxxxx_product_type() {

    class WC_Product_package extends WC_Product {

        public $product_type = 'xxxxxx';
        public function __construct( $product ) {
            parent::__construct( $product );
        }
    }
}

add_action( 'init', 'register_xxxxxx_product_type' );
然后添加您的产品类型

function add_xxxx_package_product( $types ){
   // Key should be exactly the same as in the class
   $types[ 'xxxxxx' ] = __( 'xxxxxx' );
return $types;

}

add_filter( 'product_type_selector', 'add_xxxx_package_product' );
然后将创建的类用于产品类型。
如果你没有这个,那么你将被困在
WC\u Product\u Simple

function woocommerce_product_class( $classname, $product_type ) {

    if ( $product_type == 'xxxxxx' ) { // notice the checking here.
        $classname = 'WC_Product_package';
    }

    return $classname;
}

add_filter( 'woocommerce_product_class', 'woocommerce_product_class', 10, 2 );
这就是如何做到的

首先确保扩展到
WC\u Product
的类已连接到
init

function register_xxxxxx_product_type() {

    class WC_Product_package extends WC_Product {

        public $product_type = 'xxxxxx';
        public function __construct( $product ) {
            parent::__construct( $product );
        }
    }
}

add_action( 'init', 'register_xxxxxx_product_type' );
然后添加您的产品类型

function add_xxxx_package_product( $types ){
   // Key should be exactly the same as in the class
   $types[ 'xxxxxx' ] = __( 'xxxxxx' );
return $types;

}

add_filter( 'product_type_selector', 'add_xxxx_package_product' );
然后将创建的类用于产品类型。
如果你没有这个,那么你将被困在
WC\u Product\u Simple

function woocommerce_product_class( $classname, $product_type ) {

    if ( $product_type == 'xxxxxx' ) { // notice the checking here.
        $classname = 'WC_Product_package';
    }

    return $classname;
}

add_filter( 'woocommerce_product_class', 'woocommerce_product_class', 10, 2 );

否,
$product\U type=='NameOfType'
应与product\U type\U选择器
$type
变量相关。。而不是你创建的类。。。请再次检查我的答案。。。你做错了..好吧,我现在已经更改了,但仍然不起作用..那么你没有像我在下面的回答中那样做.你能看看我的更新吗#2。Thanksok尝试更改
public$product_type='daniel'至<代码>公共$product_类型='daniel_package'否,
$product\U type==“NameOfType”
应与产品类型选择器
$type
变量相关。。而不是你创建的类。。。请再次检查我的答案。。。你做错了..好吧,我现在已经更改了,但仍然不起作用..那么你没有像我在下面的回答中那样做.你能看看我的更新吗#2。Thanksok尝试更改
public$product_type='daniel'至<代码>公共$product_类型='daniel_package'@Reigel完美,这让我摆脱了巨大的衰退。不过有一个问题,过滤器末尾的“10,2”是什么?@ChristianGröber,10是默认优先级,2是函数
“woocommerce\u product\u class”
,即
函数woocommerce\u product\u class($classname,$product\u type)
@Reigel Perfect中预期的参数数量,这让我摆脱了巨大的衰退。但有一个问题是,过滤器末尾的“10,2”代表什么?@ChristianGröber,10是默认优先级,2是函数
“woocommerce\u product\u class”
,即
函数woocommerce\u product\u class($classname,$product\u type)