Custom fields for MarketPress

I tried CustomPress as per this post https://premium.wpmudev.org/forums/topic/marketpress-custom-fields-1#post-158300
It seems to work ok though I guess it will take some "custom coding" as David mentioned.
Before I launch into that, am I heading in the right direction?

Some background:
I'm building a site for a wholesaler. He needs to add APN barcode numbers (just the number, not the barcode itself) to each product. This number will be unique for each product. He needs to have them visible with the product description for his customers to see. Then if the store he supplies to wants to add a new product to their shelves they just copy the APN and setup their stock control and pricing software ready for when the new stock arrives.

Is CustomPress the best way to add custom fields to MarketPress for my purposes?

  • globalupturn

    Hi Kimberly.

    Thanks for your quick response.

    Yes that part works fine. Now I need to get those fields visible to the customer in the product list page and the single product view.

    I just wanted to check that I was heading the right direction before customising templates etc.

    And on that issue:

    1. How do I do this with custom MarketPress template files?
    I assume from marketpress-includes/themes/Themeing_MarketPress.txt that it would involve creating a custom Product List Page (mp_productlist.php) or similar.

    2. Do I have to create this file from scratch or can I copy the standard one from somewhere?

    3. If I create it from scratch which of the functions from /marketpress/marketpress-includes/template-functions.php would I have to include to simulate the standard /store/products page?

    4. Am I on the right track here or have I missed something fundamental?

    I did a bit of searching for more documentation/forum posts on this but have not found much yet.
    If this is documented elsewhere in more detail than in marketpress-includes/themes/Themeing_MarketPress.txt feel free to point me to that.

    Thanks for your help.

    Shayne

  • globalupturn

    Well this gives me another little clue https://premium.wpmudev.org/forums/topic/marketpress-template-help#post-150115

    Why is all this so cryptic? Where's the documentation that says how to do it. In this regard WPEC is easier, just copy the template and customise away.

    Can someone at least give me an example of a few custom templates like
    mp_product.php
    mp_store.php
    mp_cart.php
    mp_orderstatus.php
    mp_productlist.php

    Yes I am ignorant here. Sorry, Gotta learn somehow.

    Any help gratefully received.

    Shayne

  • Kimberly

    Shayne,

    Have you tried to add a field to the post type via Dashboard>CustomPress>Content Types>Feilds?

    I believe that Marketpress now supports these.

    They should show up in the Add New Product form if I am not mistaken, I'll check on this.

    In the meantime could you verify this is what you are needing?

    I am not stepping over your previous post, just trying to see if there is a way to help you around coding and template files :slight_smile:

    Kimberly

  • globalupturn

    Hi Kimberly

    Yes that is fine. I see the custom fields in the Add New Product form and can add the details there.

    As I mentioned "that part works fine. Now I need to get those fields visible to the customer in the product list page and the single product view."

    Perhaps I should say now I need to get that data visible to the customer in the product list page and the single product view.

    Thanks

  • Kimberly

    Shayne,

    My apologies, you are absolutely correct!

    Kind of like giving you ice-cream an no spoon... haha

    Just as stated in the Themeing_Marketpress file:

    MarketPress searches your current theme folder for template files specific to store pages. If
    a template file does not exist it loads the theme's page template instead. Just like WP, the
    plugin will search for templates in order of priority from top to bottom. Here are possible
    file names for store templates in order:

    Single Product Page
    mp_product-PRODUCTNAME.php
    mp_product-PRODUCTID.php
    mp_product.php

    You would need to add the embed code to mp_product.php

    Does this help?

    Best,

    Kimberly

  • globalupturn

    Hi Kimberly

    I think I am a step ahead of you here.

    My question is (still) what is the "embed code" I need to add to mp_product.php (or mp_productlist.php if I wanted that too). So my key questions from this post still stand. i.e...

    2. Do I have to create this file from scratch or can I copy the standard one from somewhere?

    3. If I create it from scratch which of the functions from /marketpress/marketpress-includes/template-functions.php would I have to include to simulate the standard /store/products page?

    Can someone at least give me an example of a custom template mp_product.php?

    As I mentioned - If this is documented elsewhere in more detail than in marketpress-includes/themes/Themeing_MarketPress.txt feel free to point me to that.

  • Kimberly

    Attaching a pic of where to find the embed code .

    You can embed into MarketPress template files (as documented in marketpress-includes/themes/Themeing_MarketPress.txt).

    You don't need to create a new one, the Themeing Marketpress refers to files that are already available and being used by Marketpress.

    If you choose to create a new one to customize you can copy the existing. :slight_smile:

    Does this help?

  • globalupturn

    Ok so I think I've figured it out somewhat.

    Aaaand after I figured it out... I noticed somewhere that someone suggested taking a look at the files in the "Framemarket/Gridmarket" Wordpress theme that these good folk at WPMU Dev put together.

    Sure enuf there are examples of a bunch of the custom template files in there. Sure they probably wouldn't work flawlessly with my theme but they do give good examples of how to call the functions from /marketpress/marketpress-includes/template-functions.php etc. Some of it is easier than I thought. Still a good challenge tho. Getting the custom fields to display only when they were populated was a little tricky but once I got it right it made sense.

    So if anyone else is looking for some help on custom templates start by downloading the Framemarket/Gridmarket theme and take a look at the examples in there. This should give you something to start with.

    If you are looking for help with getting custom field data to be included in your custom templates:
    1. Download and install CustomPress from right here on WPMUDev.
    2. Use Custompress to create your custom fields and add them to your post type as per instructions here.
    3. Then, and this is a key point, hover your mouse pointer over the name of your shiny new custom field and click on the "embed code" link that appears... oh that embed code!
    4. Curse the stupid jackass who thought it was a good idea to hide links untill you hover over them! That miserable git must have been smoking some bad stuff at the time they came up with that brainwave... and is probably not a friend of anyone who is vision impaired.
    5. Copy the actual "embed code" that appears when you click on the "embed code link" (looks something like this <?php echo get_post_meta( $post->ID, 'ct_xxx_text_33c5', true ); ?>).
    6. Paste this code into your custom template wherever you want it to appear.
    7. Curse passionately if the custom field data does not appear in your browser... but don't panic yet.
    8. Read about custom fields in the wordpress codex here and note that:

    $post_id is the ID of the post you want the meta values for. Use $post->ID to get a post's ID within the $post variable scope. Use get_the_ID() to retrieve the ID of the current item in the WordPress Loop.

    SO if you are placing your embed code into the loop you need to change it from something like this:
    <?php echo get_post_meta( $post->ID, 'ct_xxx_text_33c5', true ); ?>
    to something like this:
    <?php echo get_post_meta( get_the_ID(), 'ct_xxx_text_33c5', true ); ?>
    9. Give you self a high five when your custom field miraculously appears in your browser.
    10. Notice that it is 2.30 in the morning and crawl into bed.

    If you follow that you should be well on your way to solving this mystery that WPMUDev hasn't quite documented fully.
    Pity no one could direct me to this info a little earlier.

    Still as they say "What doesn't fry your brain makes you stronger"... or something like that.

  • globalupturn

    In case anyone is interested, here is some rough code that I used to get the right stuff appearing in one of my custom templates (APN & TUN are my custom fields):

    <!-- post content -->
    <div class="entry-content clearfix">
    	<?php mp_product_image(); ?>
    	<?php the_content(); ?>
    	<!-- Show APN or TUN if exists-->
    	<?php $apn = get_post_meta(get_the_id(), 'ct_APN_text_33c5', true); ?>
    	<?php if($apn)  echo "<strong>APN: </strong>", $apn, "<br />"; ?>
    	<?php $tun = get_post_meta(get_the_id(), 'ct_TUN_text_d060', true); ?>
    	<?php if($tun)  echo "<strong>TUN: </strong>", $tun, "<br />"; ?>
    	<!-- Show GST Exempt if applicable -->
    	<?php $plustax = get_post_meta(get_the_id(), 'mp_is_special_tax', true); ?>
    	<?php if($plustax==1)  echo "GST Exempt <br />"; ?>
    	<!-- Show Price & Add to Cart button (with quantity field) -->
    	<?php mp_product_price(); ?>
    	<?php mp_buy_button( true, 'single'); ?>
    </div>

    I probably made some php noob mistakes in there and it could do with some extra divs with classes if I want to add more styling.
    "mp_is_special_tax" is a built in MarketPress meta field and is handy for me because I only have 2 tax rates: 10% or 0% (GST exempt) hence the <!-- Show GST Exempt if applicable --> section.

  • Kimberly

    Thank you for an incredible reply and major points coming your way! I will mark this in my favorites for reference! I am only starting to learn about php myself so this is a great read for me as well. :slight_smile:.
    I am very sorry no one else was able to get here before me but am so very glad you got it sorted, to your own benefit and those of many others.
    We are working on a rewrite of much of our documentation and I will be sure to note to whomever does do CustomPress the need for more documentation on this exact issue, as we have had others before you with the same confusion.
    Best and THANK YOU for being a WPMU member :slight_smile:

    Kimberly

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.