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.

Read more here: WP custom post type cant already add to cart in woocommerce 3.0 above


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: