How to add “Add to cart” function for post with type is ‘post’ in WooCommerce?
-
I have already added “Add to cart” button (for post with type = post) with same POST end point like “Add to cart” function in the post (with type = product), but cannot working properly, like that:
`<?php
add_filter(‘woocommerce_get_price’,’reigel_woocommerce_get_price’,20,2);
function reigel_woocommerce_get_price($price,$post){
if ($post->post->post_type === ‘post’)
$price = get_post_meta($post->id, “price”, true);
return $price;
}
add_filter(‘the_content’,’rei_add_to_cart_button’, 20,1);
function rei_add_to_cart_button($content){
global $post;
if ($post->post_type !== ‘post’) {return $content; }ob_start();
?>
<form action=”” method=”post”>
<input name=”add-to-cart” type=”hidden” value=”<?php echo $post->ID ?>” />
<input name=”quantity” type=”number” value=”1″ min=”1″ />
<input name=”submit” type=”submit” value=”Add to cart” />
</form>
<?phpreturn $content . ob_get_clean();
}
?>
Reference: http://reigelgallarde.me/programming/how-to-add-custom-post-type-to-woocommerce/Thank you for your support!
The topic ‘How to add “Add to cart” function for post with type is ‘post’ in WooCommerce?’ is closed to new replies.