我仍然可以通过在'woocommerce_product_class'中添加过滤器,在WooCommerce 2.6中将自定义帖子类型添加到购物车
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());
Run Code Online (Sandbox Code Playgroud)
不幸的是,这还不适用于最新版本的WooCommerce.有人请帮我解决这个问题的解决方案吗?任何建议,评论和解决方案都非常感谢.