https://docs.google.com/file/d/0b6n5mn7suesdoef0ukhymjfysda/edit
thanks和ward chirag
您可以在几秒钟内通过使用此wooCommerce(附加组件,数据,选项,预订和约会)轻松地做到这一点。 或使用此代码:
// #1 Add New Product Type to Select Dropdown
add_filter( 'product_type_selector', 'wpsaad_add_custom_product_type' );
function wpsaad_add_custom_product_type( $types ){
$types[ 'custom' ] = 'Custom product';
return $types;
}
// --------------------------
// #2 Add New Product Type Class
add_action( 'init', 'wpsaad_create_custom_product_type' );
function wpsaad_create_custom_product_type(){
class WC_Product_Custom extends WC_Product {
public function get_type() {
return 'custom';
}
}
}
// --------------------------
// #3 Load New Product Type Class
add_filter( 'woocommerce_product_class', 'wpsaad_woocommerce_product_class', 10, 2 );
function wpsaad_woocommerce_product_class( $classname, $product_type ) {
if ( $product_type == 'custom' ) {
$classname = 'WC_Product_Custom';
}
return $classname;
}