Support » Plugin: WooCommerce » 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>
    <?php

    return $content . ob_get_clean();
    }
    ?>
    Reference: http://reigelgallarde.me/programming/how-to-add-custom-post-type-to-woocommerce/

    Thank you for your support!

Viewing 3 replies - 1 through 3 (of 3 total)
  • @mrzoobit I’m not really sure why you are trying to add “posts” to the cart. “products” are what WooCommerce deals with, not regular blog posts.

    @anphira because @mrzoobit wants to sell his/her blog posts i think.

    @mrzoobit i experience the same problems.
    maybe woocommerce changed something in it’s code because when checking the called filters via:

    add_action( 'all', create_function( '', 'var_dump( current_filter());' ) );

    the woocommerce_get_price filter isn’t called anymore.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add “Add to cart” function for post with type is ‘post’ in WooCommerce?’ is closed to new replies.