I can still add custom post type to cart in WooCommerce 2.6 just by adding a filter to 'woocommerce_product_class'
function wc_product_class( $class, $product_type, $post_type ) {
if( 'my_custom_post_type_slug' == $post_type )
$class = 'WC_Product_Simple';
return $class;
}
add_filter( 'woocommerce_product_class', 'wc_product_class', 10, 3);
//This will echo the carti item id
echo WC()->cart->add_to_cart($custom_post_type_id, $quantity, null, null, array());
Unfortunately this doesn't already work on the latest version of WooCommerce. Would somebody please help me what is the solution for this issue? Any suggestions, comments, solutions are much appreciated.
I'm selling a plugin that would enable to use Custom Post Type as "product" of WooCommerce. I did a lot of work on that.
But this is the most important part.
You have to create your own data store, like this:
first create a class that extends to
WC_Product_Data_Store_CPT
. The idea is to overwrite the existing function of this class that check the post type. I foundread
andget_product_type
that does the checking.after that, add a filter to
woocommerce_data_stores
and use your class.with that, you'll be able to add a post type of
birds
to cart. But will not actually be a success add to cart. Because there's no price, cart will reject it.To solve that, you need another filter. Below is a simple way of adding the price.
Once that's done, you'll have success adding to cart.