admin管理员组

文章数量:1406926

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic.

Closed 11 years ago.

Improve this question

I want to add a new custom "product type" to woocommerce plugin:

Tried to duplicate one of currently exist product type files (woocommerce template structure) as a new file (file name and inside commented name) but not worked!

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic.

Closed 11 years ago.

Improve this question

I want to add a new custom "product type" to woocommerce plugin:

Tried to duplicate one of currently exist product type files (woocommerce template structure) as a new file (file name and inside commented name) but not worked!

Share Improve this question asked Oct 26, 2013 at 22:19 AminoAmino 3232 gold badges5 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 20

The add to cart template is only 1 of the many things you'll need to do. Each product type has it's own class in the /includes/ folder. Each one extends the WC_Product class.

To add items to the list you've screencapped (which is on the admin side and not the front-end, unlike the add-to-cart.php template, you will need to filter product_type_selector.

add_filter( 'product_type_selector', 'wpa_120215_add_product_type' );
function wpa_120215_add_product_type( $types ){
    $types[ 'your_type' ] = __( 'Your Product Type' );
    return $types;
}

then you'll need to declare your product class. The standard naming system is WC_Product_Type_Class so in this example it would be:

class WC_Product_Your_Type extends WC_Product{
    /**
     * __construct function.
     *
     * @access public
     * @param mixed $product
     */
    public function __construct( $product ) {
        $this->product_type = 'your_type'; // Deprecated as of WC3.0 see get_type() method
        parent::__construct( $product );
    }

     /**
     * Get internal type.
     * Needed for WooCommerce 3.0 Compatibility
     * @return string
     */
    public function get_type() {
        return 'your_type';
    }
}

You are asking a very complicated question and I can't provide a more complete answer. Hopefully this sets you on the right path. I highly encourage you to read the code in WooCommerce. It is very well commented and you can see how they are handling the different product types.

Edit Added WC3.0 compatibility to product type class.

本文标签: customizationHow to add a new product type on woocommerce product types