Integrating with MarketPress

I am looking at the feature in CoursePress that automatically creates a MarketPress product to sell the courses. I need to automatically create a MarketPress product via a custom post type that is to sell events. Do you know of a tutorial for this?

I am using a Custom Post Type that I have created. I am very familiar with php/wordpress. Coding is not an issue. I was just wondering if there was, maybe, a tutorial somewhere that would speed up the learning curve of MarketPress.

Advanced Custom Fields makes it easy to link the CPT to a Product, but it just creates confusion for my client. She doesn't like having to create a product first, then link it to the custom post type. So I would like it to work the same way as CoursePress & MarketPress do currently.

  • James Morris
    • WordPress Enthusiast

    Hello Social Power,

    I hope you are well today.

    This is a great question and could be useful a wide number of projects.

    Since this is a bit more of an advanced coding question, I'm going to ping our SLS team (code experts) and ask them for their feedback on this issue. I'll update this ticket as soon as I hear back from them.

    Best regards,

    James Morris

  • Panos
    • SLS

    Hi Social Power ,

    It's not that hard to accomplish but it requires some understanding on how MarketPress works.

    First thing to do when creating a new post of you CPT is to also create a new product and add a price to it. For storing the price you can use the regular_price as meta key of the product:
    update_post_meta( $product_id, 'regular_price', $price );

    After creating the new product associate the product id with the custom post type, eg by using the product_id as a meta key in your cpt:
    update_post_meta( $post_id, 'product_id', $product_id );

    Only thing left is to display the add to cart button in the cpt page. The add to cart button will be called with the associated product id:

    $shortcode = sprintf( '[mp_buy_button product_id="%s"]', $product_id );
    return $content . '<div class="wpmudev-mpi add_to_cart">' . do_shortcode( $shortcode ) . '</div>';

    I have prepared a working sample which you can find here:

    I have used the cpt books in the example so you will need to change it :slight_smile:

    Hope this helps!

    • Social Power
      • WPMU DEV Initiate

      James and Panos,

      Thanks for your replies! This will work for what I need. Like you said, Panos, I just need to spend some time inside MarketPress. However, this solution is exactly what I was looking to do.

      Keep up the great work and great support!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.