
WooCommerce创建新的产品类型
默认情况,WooCommerce的产品类型有:Simple, Variable, Grouped and External 这四种;

在实际应用中,我们可能需要创建新的产品类型:
function fjj_add_custom_product_type( $types ){
$types[ 'custom' ] = 'Custom product';
return $types;
}
add_filter( 'product_type_selector', 'fjj_add_custom_product_type' );
function fjj_create_custom_product_type(){
class WC_Product_Custom extends WC_Product {
public function get_type() {
return 'custom';
}
}
}
add_action( 'init', 'fjj_create_custom_product_type' );
function fjj_woocommerce_product_class( $classname, $product_type ) {
if ( $product_type == 'custom' ) {
$classname = 'WC_Product_Custom';
}
return $classname;
}
add_filter( 'woocommerce_product_class', 'fjj_woocommerce_product_class', 10, 2 );