Roy Vincent Niepes

Blog and Portfolio

Posted on by

Woocommerce product is not purchasable


Woocommerce product is not purchasable

If you encountered this error, probably you’ve added the product programmaticaly.
I, until now still wondering why it’s not purchasable whenever the product is added programmaticaly using the wp_insert_post function of wordpress.

Anyway, I solved the issue by making the products purchasable whatever it is, using woocomerce filter.

function wc_is_purchasable( $return ) {
 return true;
 }
 add_filter( 'woocommerce_is_purchasable', 'wc_is_purchasable', 10, 1 );

Just put this in your functions.php and it will solve your problem.

It was still a mistery to me what’s causing this issue. I’ve checked and compared the postmeta between the product that has been added programmaticaly using wp_insert_post and a product added with woocommerce add product page and there entry was exactly the same.

If ever you know why and what’s causing and missing to it and how to solve this issue without changing the return of is_purchasble function, I’ll be very happy if you share it too! 🙂

 

 

— Update

 

Hi Guys, recently I’ve figured out that the problem was because the price is empty….
This code solved my problem. Hope it helps someone.

 

function wc_default_price($price) {
if(empty($price) || $price == null || $price == "") {
$price = 1;
}
return $price;
}

add_filter('woocommerce_get_price','wc_default_price', 10,1);

 

comments powered by Disqus