Market lets you sell products online using the Wordpress platform.

You must be logged in to post Login

Search Forums:


 






Affiliate Items

UserPost

4:01 pm
May 9, 2008


Market Admin

Admin

posts 2765

Post edited 8:20 pm - August 13, 2009 by Market Admin


The purpose of this modication is to change the default action of the buy now button to forward the purchasing of an item to an affiliate site.

(changes for Market version 3.0)


Portions of this post / hack thanks to a member ;)


I have replaced the paypal functionality in the div tag for the buy button with another custom field in the single.php template page.


You need to replace this tag in single.php:


<?php if (have_posts()) : while (have_posts()) : the_post(); // check for product thumbs

$thumb = get_post_meta($post->ID, 'pi1', $single = true); // check for product thumbs

$thumb2 = get_post_meta($post->ID, 'pi2', $single = true); // check for product thumbs

$thumb3 = get_post_meta($post->ID, 'pi3', $single = true); // check for product large image

$pli = get_post_meta($post->ID, 'pli', $single = true); // check for item price

$price = get_post_meta($post->ID, 'price', $single = true); // check items specs

$specs = get_post_meta($post->ID, 'specs', $single = true); ?>


with:

<?php if (have_posts()) : while (have_posts()) : the_post(); // check for product thumbs

$thumb = get_post_meta($post->ID, 'pi1', $single = true); // check for product thumbs

$thumb2 = get_post_meta($post->ID, 'pi2', $single = true); // check for product thumbs

$thumb3 = get_post_meta($post->ID, 'pi3', $single = true); // check for product large image

$pli = get_post_meta($post->ID, 'pli', $single = true); // check for item price

$price = get_post_meta($post->ID, 'price', $single = true); // check items specs

$specs = get_post_meta($post->ID, 'specs', $single = true);

$buy = get_post_meta($post->ID, 'buy', $single = true); ?>


As you can see I am calling the custom field "buy". Now you need to find the buy div tag:

<div class="buy">lots of paypal code</div>


strip out the paypal code in there and replace with:


<div class="buy"><a href="<?php echo $buy; ?>"><img src="<?php bloginfo('template_directory'); ?>/imgs/bn.gif" alt="buy now" /></a></div>

Upload the single.php file and you should be ready to go.


Then when you are creating a post, create a custom field called with the key as "buy" and the value as the url to your affiliate site. (use http to make sure that the link works correctly)


2:07 am
May 10, 2008


gmedia

Member

posts 30

That works perfectly. Thanks!

3:34 am
June 29, 2008


spicer

New Member

posts 1

Hi AJ,


Does this modification work on MK3?

The reason for the question is I've just tried it

and I'm getting a


"Parse error: syntax error, unexpected T_ENDWHILE on line 98"


Any assistance is greatly appreciated.


Thanks!

Spicer

8:17 pm
October 1, 2008


integrusmedia

Member

posts 7

spicer said:

Hi AJ,


Does this modification work on MK3?

The reason for the question is I've just tried it

and I'm getting a


"Parse error: syntax error, unexpected T_ENDWHILE on line 98"


Any assistance is greatly appreciated.


Thanks!

Spicer


Spicer,

I got it to work. I also added some extra 6 lines of additional code to make it so when I have an affiliate link present, it will automatically hide the "add to cart" button.

1:20 am
October 5, 2008


TurboMember

New Member

posts 1

@ integrusmedia: are you willing to share the snippet you used to kill the 'add to cart' on affiliate products, or better yet... how to disable the cart altogether?

I'd only like to use the posting, display, and management aspects of the mk3 theme and mpm plugin, while including my own special links. Any chance your solution can help, as I'd almost prefer to permanently kill the 'buy now' and 'add to cart' functionality via commenting, preferring to use another system for managing the sales (was quite extensive and expensive, but worth the cost), and only using links to get folks into the system.

TYIA

TurboMember

2:51 pm
October 22, 2008


integrusmedia

Member

posts 7

TurboMember said:

@ integrusmedia: are you willing to share the snippet you used to kill the 'add to cart' on affiliate products, or better yet… how to disable the cart altogether?

I'd only like to use the posting, display, and management aspects of the mk3 theme and mpm plugin, while including my own special links. Any chance your solution can help, as I'd almost prefer to permanently kill the 'buy now' and 'add to cart' functionality via commenting, preferring to use another system for managing the sales (was quite extensive and expensive, but worth the cost), and only using links to get folks into the system.

TYIA

TurboMember


TurboMember,

Sure I'll share my information to the masses. For my site, I'm selling my own products, but I am also selling Amazon affiliate products with my amazon-associate tags. So if it's an item that I'm selling, the user sees an "add to cart" button. If it is an amazon item, users see a "buy now" button. Here's what I did below.

I first followed AJ's instructions located above:

$specs = get_post_meta($post->ID, 'specs', $single = true); // check items shipping
$buy = get_post_meta($post->ID, 'buy', $single = true); //added buy variable for for use with custom fields
$shipping = get_post_meta($post->ID, 'shipping', $single = true); $size = get_post_meta($post->ID, 'size', $single = true);

For affiliate links, I knew I wasn't going to need to pass variables for size and color so I removed a chunk of code:

 <?php // if there's a price and the item is still for sale
if($price !== '') : ?>
  <div class="buy">
 
    <!– hiding original buy form code –>
   
<?php // Removed a chunk of code here. Didn't need it for affiliate links"
     
      <!– end of hiding original buy form code –> 
     
          <!–Start Vcart Code–>
    <form class="lsf" method="post" action="<?php bloginfo('template_directory'); ?>/ajCart/cart.php" >

I also removed the drop-down boxes (for size and color) that displayed under the original "buy now" button:

 <input type="hidden" name="currency_code" value="USD">

<input type="hidden" name="return" value="<?php bloginfo('url'); ?>">
      <input type="hidden" name="cancel_return" value="<?php bloginfo('url'); ?>">
      <table>
        <tr>
          <?php if (!empty($size)){

            echo "

              <td> <!– You may hate me –> </td>

              <td> <!– Cuz it ain't no lie –> </td> 
        </tr>
        <tr>
          <td> <!– Bye-Bye-BYE! –></td>

              <td> <!– Yes I'm an Nsync Fan –>  </td>  "; } ?>
        </tr>
      </table>


I then had to figure out how to display the different buttons ("buy now" for affiliate items, or "add to cart" for my own items). Since I'm in my first semester of PHP at school, I did it in a very "ghetto way" (see bolded section):


 <td> <!– Yes I'm an Nsync Fan –> </td>  "; } ?>
        </tr>
      </table>
  
  <?php if($buy !== '' ) {
        echo '<a href="' ?>
        <?php echo $buy; ?>"> //Affiliate URL Specified in buy custom field
        <? echo'<img src="' ?>
        <? bloginfo('template_directory') ?>
        <? echo '/imgs/bn.gif" border="0″ alt="buy now" /></a>'; ?>
      <?php } else {
        echo '' ;
        }
        ?>

     
     
    </form>
    <!–Start Vcart Code–>
    <form class="crtAdd rsf" method="post" action="<?php bloginfo('template_directory'); ?>/ajCart/cart.php" >
      <input type="hidden" name="cmd" value="_cart">
      <input type="hidden" name="add" value="1″>
      <input type="hidden" name="quantity" value="1″>


One of the last things I had to do was hide or show "Add to Cart" depending the situation (in bold):

            if (isset($colorlist[10])) { echo "<option value=\"$colorlist[10]\">$colorlist[10]</option>"; }

              echo "

                </select>

              </td>"; } ?>
        </tr>
      </table>
     
       <?php if($buy !== '' ) {
        echo ''; ?>
      <?php } else {
        echo '<input type="image" src="' ?>
        <?php bloginfo('template_directory'); ?>
        <? echo '/imgs/atc.gif" class="pp" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">' ;
        }
        ?>

     
     
    </form>
    <!--End Vcart Code-->
    <div style="clear: both"></div>
  </div>
  <?php else : ?>
  <?php endif; ?>
</div>
<?php else : ?>
<?php get_sidebar(); ?>
<div class="news">


That's about it. If you need anymore help, you'll have to pay me. Wink
AJ, I need a high-5 or something from ya. lol


2:35 pm
October 31, 2008


Market Admin

Admin

posts 2765

What can I say integrusmedia, you rock!   Thank you for your contribution to the community.

(Virtual high-5)

8:53 pm
November 25, 2008


cotaco

New Member

posts 2

Wow I am so new to this, I just got the theme but never expected to be si difficult to post affiliate links from Amazon, it is the only products I got know.

http://www.rebelcool.com/


It is other way to get it correctly? Some instructions in other post? Please help!


(sorry my english)

10:34 pm
January 11, 2009


ilovenaps

Member

posts 4

This is all a tad confusing, any chance someone could just upload the whole code so I could just do a simple copy and paste ? I'm interested in selling Amazon products with Market Theme.

2:36 pm
February 3, 2009


integrusmedia

Member

posts 7

ilovenaps said:

This is all a tad confusing, any chance someone could just upload the whole code so I could just do a simple copy and paste ? I'm interested in selling Amazon products with Market Theme.


It's not that confusing. Here's my single.php code in its entirety:

<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); // check for product thumbs
$thumb = get_post_meta($post->ID, 'pi1', $single = true);  // check for product thumbs
$thumb2 = get_post_meta($post->ID, 'pi2', $single = true); // check for product thumbs
$thumb3 = get_post_meta($post->ID, 'pi3', $single = true); // check for product large image
$pli = get_post_meta($post->ID, 'pli', $single = true); // check for item price
$price = get_post_meta($post->ID, 'price', $single = true); // check items specs
$specs = get_post_meta($post->ID, 'specs', $single = true); // check items shipping
$buy = get_post_meta($post->ID, 'buy', $single = true);
$shipping = get_post_meta($post->ID, 'shipping', $single = true); $size = get_post_meta($post->ID, 'size', $single = true);

$sizelist = explode(" ", $size);

$color = get_post_meta($post->ID, 'color', $single = true);

$colorlist = explode(" ", $color); ?>
<?php // if there's a thumbnail
if($pli !== '') : ?>

<div class="news">
  <div class="breadcrumbs">
    <p><strong><a href="<?php bloginfo('url'); ?>">
      <?php bloginfo('name'); ?>
      </a></strong> &#8250;
      <?php the_category(' '); ?>
      &#8250;
      <?php the_title(); ?>
    </p>
  </div>
  <div class="post" id="post-<?php the_ID(); ?>">
    <div class="mi"> <img src="<?php bloginfo('template_directory'); ?>/phpthumb/phpThumb.php?src=<?php echo $pli; ?>&w=350&h=350&iar=1" alt="<?php the_title(); ?>" /> </div>
    <div class="tr">
      <?php // if there's a thumbnail
if($thumb !== '') { ?>
      <?php echo $thumb; ?>
      <?php } // end if statement

// if there's not a thumbnail
else { echo ''; } ?>
      <?php // if there's a thumbnail
if($thumb2 !== '') { ?>
      <?php echo $thumb2; ?>
      <?php } // end if statement

// if there's not a thumbnail
else { echo ''; } ?>
      <?php // if there's a thumbnail
if($thumb3 !== '') { ?>
      <?php echo $thumb3; ?>
      <?php } // end if statement

// if there's not a thumbnail
else { echo ''; } ?>
    </div>
  </div>
</div>
<div class="desc">
  <h2>
    <?php the_title(); ?>
    <?php // if there is a price at the moment show it
if($price !== '') { ?>
    <span class="price"><strong>$</strong><?php echo $price; ?></span>
    <?php } // end if statement

// if there's not a price or item is sold out
else { echo '<span class="sold">Sold Out</span>'; } ?>
  </h2>
  <?php the_content(); ?>
  <div class="specs">
    <p><strong>Additional Details:</strong> <?php echo $specs; ?></p>
  </div>
  <?php // if there's a price and the item is still for sale
if($price !== '') : ?>
  <div class="buy">
 
    <!-- hiding original buy form code -->
   
 
     
      <!-- end of hiding original buy form code --> 
     
          <!--Start Vcart Code-->
    <form class="lsf" method="post" action="<?php bloginfo('template_directory'); ?>/ajCart/cart.php" >
      <input type="hidden" name="cmd" value="_cart">
      <input type="hidden" name="add" value="1">
      <input type="hidden" name="quantity" value="1">
      <input type="hidden" name="business" value="<?php bloginfo('admin_email'); ?>">
      <input type="hidden" name="item_name" value="<?php the_title(); ?>">
      <input type="hidden" name="amount" value="<?php echo $price; ?>">
      <input type="hidden" name="handling" value="" />
      <input type="hidden" name="handling_cart" value="" />
      <input type="hidden" name="shipping" value="<?php echo $shipping; ?>" />
      <input type="hidden" name="shipping2" value="0" />
      <input type="hidden" name="on0" value="Shipping" />
      <input type="hidden" name="os0" value="" />
      <input type="hidden" name="lc" value="US">
      <input type="hidden" name="currency_code" value="USD">
      <input type="hidden" name="return" value="<?php bloginfo('url'); ?>">
      <input type="hidden" name="cancel_return" value="<?php bloginfo('url'); ?>">
      <table>
        <tr>
          <?php if (!empty($size)){

            echo "

              <td> </td>

              <td>  </td> 
        </tr>
        <tr>
          <td></td>

              <td>  </td>  "; } ?>
        </tr>
      </table>
    
      <?php if($buy !== '' ) {
        echo '<a href="' ?>
        <?php echo $buy; ?>">
        <? echo'<img src="' ?>
        <? bloginfo('template_directory') ?>
        <? echo '/imgs/bn.gif" border="0" alt="buy now" /></a>'; ?>
      <?php } else {
        echo '' ;
        }
        ?>

     
     
    </form>
    <!--Start Vcart Code-->
    <form class="crtAdd rsf" method="post" action="<?php bloginfo('template_directory'); ?>/ajCart/cart.php" >
      <input type="hidden" name="cmd" value="_cart">
      <input type="hidden" name="add" value="1">
      <input type="hidden" name="quantity" value="1">
      <input type="hidden" name="business" value="<?php bloginfo('admin_email'); ?>">
      <input type="hidden" name="item_name" value="<?php the_title(); ?>">
      <input type="hidden" name="amount" value="<?php echo $price; ?>">
      <input type="hidden" name="handling" value="" />
      <input type="hidden" name="handling_cart" value="" />
      <input type="hidden" name="shipping" value="<?php echo $shipping; ?>" />
      <input type="hidden" name="shipping2" value="0" />
      <input type="hidden" name="on0" value="Shipping" />
      <input type="hidden" name="os0" value="" />
      <input type="hidden" name="lc" value="US">
      <input type="hidden" name="currency_code" value="USD">
      <input type="hidden" name="return" value="<?php bloginfo('url'); ?>">
      <input type="hidden" name="cancel_return" value="<?php bloginfo('url'); ?>">
      <table>
        <tr>
          <?php if (!empty($size)){

            echo "

              <td><input type=\"hidden\" name=\"on0\" value=\"Size\"/>

                Size:</td>

              <td><select name=\"os0\" class=\"field\" >

                 

            <option value=\"$sizelist[0]\">$sizelist[0]</option>";

                 

            if (isset($sizelist[1])) { echo "<option value=\"$sizelist[1]\">$sizelist[1]</option>"; }

            if (isset($sizelist[2])) { echo "<option value=\"$sizelist[2]\">$sizelist[2]</option>"; }

            if (isset($sizelist[3])) { echo "<option value=\"$sizelist[3]\">$sizelist[3]</option>"; }

            if (isset($sizelist[4])) { echo "<option value=\"$sizelist[4]\">$sizelist[4]</option>"; }

            if (isset($sizelist[5])) { echo "<option value=\"$sizelist[5]\">$sizelist[5]</option>"; }

            if (isset($sizelist[6])) { echo "<option value=\"$sizelist[6]\">$sizelist[6]</option>"; }

            if (isset($sizelist[7])) { echo "<option value=\"$sizelist[7]\">$sizelist[7]</option>"; }

            if (isset($sizelist[8])) { echo "<option value=\"$sizelist[8]\">$sizelist[8]</option>"; }

            if (isset($sizelist[9])) { echo "<option value=\"$sizelist[9]\">$sizelist[9]</option>"; }

            if (isset($sizelist[10])) { echo "<option value=\"$sizelist[10]\">$sizelist[10]</option>"; }

             echo "   </select>

              </td>"; } ?>
        </tr>
        <tr>
          <td><?php if (!empty($color)){

            echo "<input type=\"hidden\" name=\"on1\" value=\"Color\"/>

                Color:</td>

              <td><select name=\"os1\" class=\"field\">

             

            <option value=\"$colorlist[0]\">$colorlist[0]</option>";

           

            if (isset($colorlist[1])) { echo "<option value=\"$colorlist[1]\">$colorlist[1]</option>"; }

            if (isset($colorlist[2])) { echo "<option value=\"$colorlist[2]\">$colorlist[2]</option>"; }

            if (isset($colorlist[3])) { echo "<option value=\"$colorlist[3]\">$colorlist[3]</option>"; }

            if (isset($colorlist[4])) { echo "<option value=\"$colorlist[4]\">$colorlist[4]</option>"; }

            if (isset($colorlist[5])) { echo "<option value=\"$colorlist[5]\">$colorlist[5]</option>"; }

            if (isset($colorlist[6])) { echo "<option value=\"$colorlist[6]\">$colorlist[6]</option>"; }

            if (isset($colorlist[7])) { echo "<option value=\"$colorlist[7]\">$colorlist[7]</option>"; }

            if (isset($colorlist[8])) { echo "<option value=\"$colorlist[8]\">$colorlist[8]</option>"; }

            if (isset($colorlist[9])) { echo "<option value=\"$colorlist[9]\">$colorlist[9]</option>"; }

            if (isset($colorlist[10])) { echo "<option value=\"$colorlist[10]\">$colorlist[10]</option>"; }

              echo "

                </select>

              </td>"; } ?>
        </tr>
      </table>
     
       <?php if($buy !== '' ) {
        echo ''; ?>
      <?php } else {
        echo '<input type="image" src="' ?>
        <?php bloginfo('template_directory'); ?>
        <? echo '/imgs/atc.gif" class="pp" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">' ;
        }
        ?>
     
     
    </form>
    <!--End Vcart Code-->
    <div style="clear: both"></div>
  </div>
  <?php else : ?>
  <?php endif; ?>
</div>
<?php else : ?>
<?php get_sidebar(); ?>
<div class="news">
  <div class="breadcrumbs">
    <p><strong><a href="<?php bloginfo('url'); ?>">
      <?php bloginfo('name'); ?>
      </a></strong> &#8250;
      <?php the_category(' '); ?>
      &#8250;
      <?php the_title(); ?>
    </p>
  </div>
  <div class="post" id="post-<?php the_ID(); ?>">
    <h2>
      <?php the_title(); ?>
    </h2>
  </div>
  <?php the_content(); ?>
  <?php comments_template(); ?>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
<?php get_footer(); ?>

If you're still confused you're welcome to hire out a PHP Developer from rentacoder.com. To assist you with your customization needs.


1:40 pm
February 15, 2009


ilovenaps

Member

posts 4

Many thanks for posting the code, it seems to be working, no errors or anything.

But I think myself and other users would still benefit from a guide on exactly how to post an Amazon item. It was the main reason I purchased Market Theme was from the promise of easy Amazon intergration but I'm still having trouble figuring this out.

I created a new post
I added the custom "buy" field, with my Amazon Aff. Link.
And now when I "preview" nothing really happens. Just has my "test post" text and no buy now button or displaying of the sizes.


So how exactly do you create a Amazon link in your store once you've edited the template files?

1:44 pm
February 15, 2009


ilovenaps

Member

posts 4

Ok I figured it out I think..................

1:42 pm
February 20, 2009


integrusmedia

Member

posts 7

ilovenaps said:

Ok I figured it out I think..................


Did you still need some advice on how to do it?  I know that one thing is for certain, this theme does not integrate with Amazon's affiliate service at all.  I manually pick and choose the Amazon items I wish to feature, then write my own creative copy describing the product, then link the "Buy Now" button to the Amazon product page with my affiliate tags.

I had wrote a PHP script that did most of this, but Amazon asked me very nicely to stop using it.

3:05 pm
May 13, 2009


jon315

New Member

posts 2

This is a super helpful post...Thanks to integrusmedia!

The only thing that's not working for me is the 'Buy Now' button image. How do I get that to work?

My code on the 'single.php' page is the same as integrusmedia's above (I just copy and pasted it).

11:04 am
August 10, 2009


The Q

Member

posts 8

jon315 said:

This is a super helpful post...Thanks to integrusmedia!

The only thing that's not working for me is the 'Buy Now' button image. How do I get that to work?

My code on the 'single.php' page is the same as integrusmedia's above (I just copy and pasted it).


Did anyone figure this out?

4:37 pm
August 13, 2009


ibexy

Member

posts 23

i have copied and pasted the single.php above but i still cant get amazon affiliate links to work on my posts. I have followed all the instructions above but the "buy" link is not jus showing. HELP please :(

8:22 pm
August 13, 2009


Market Admin

Admin

posts 2765

This topic is continued on a newer post:

http://www.markettheme.com/for.....e-products

10:28 am
October 11, 2009


Su

Member

posts 33

Since I want to mix affiliate and my own sales, I returned to this post by ingrusmedia. The newer post is only for affiliate links. Well, I'm in a pickle now as my links to the products have broken. I am getting this error . It occured on the last edit to show or hide the button, (I check the site after each edit) and wasn't corrected by deleting the edit. I am going to post this under that post as well.

   Parse error: syntax error, unexpected T_ELSE in /home/content/69/5036069/html/wp-content/themes/mk3/single.php on line 246

11:48 am
December 8, 2009


cmoreton

Member

posts 9

is this the code to use when we want both add to cart and buy buttons?

I tried the code above, added a buy custom field and an url.

Clicked save, when I viewed the post the add to cart button was still there.

Can anybody help please?

2:17 pm
February 18, 2010


integrusmedia

Member

posts 7

Hey guys, I'm back from Japan if you still need help with this discussion.


-Aristotle