Jump to content


Replying to Shortcode For Exchange?


Post Options

  or Cancel


Topic Summary

Craig Brissell

Posted 21 September 2014 - 07:52 PM

Thanks Guys very much for your help. I really appreciate it.

Robertsing

Posted 19 September 2014 - 03:49 PM

Hi Craig... out the door for the weekend, so a quick reply...

I used the last code as noted... and was wrapped in <?php and before any closing ?>... nothing else in the file.  Stephen


<?php
function
my_it_exchange_add_to_cart($atts) {

extract(shortcode_atts(array(
                 "product_id" => null
), $atts));

it_exchange_set_product( $product_id );

$output = "<div class='my_it_itemdescription'>Item: " . it_exchange( 'product', 'get-description' ) . "</div>";
$output .= "<div class='my_it_price'>Price: " . it_exchange( 'product', 'get-base-price' ) . "</div>";
$output .= "<div class='my_it_buy-now'>" .it_exchange( 'product', 'get-purchase-options', array( 'add-to-cart-edit-quantity' => true, 'buy-now-edit-quantity' =>true ) ) . "</div>";

return $output;
}
add_shortcode( 'add-to-cart', 'my_it_exchange_add_to_cart' );
?>

Ronald

Posted 18 September 2014 - 04:34 PM

@Craig,

item can be found in this line:

$output = "<div class='my_it_itemdescription'>Item: " . it_exchange( 'product', 'get-description' ) . "</div>";

You can use css to change the color and style of the buttons. Use Firebug to inspect the code, and you can override the css by adding the appropriate css at the end of your child themes stylesheet style.css (as that is where the button inherits the styling from), see image:

Posted Image

Ronald

Ronald

Posted 18 September 2014 - 04:28 PM

View PostRobertsing, on 18 September 2014 - 02:08 AM, said:

I tried adding to my child theme as describes.

Leaves me with a blank white site. everything gone.

i started from scratch with a trivial theme and no additions in the child except the noted functions.php code.

Hi,

did you add the code inside php tags? So after an opening <?php and before any closing ?>

If so, can you add the code and then share the entire functions.php in a pastebin (http://pastebin.com/) and send me the link to that pastebin?

Ronald

Craig Brissell

Posted 18 September 2014 - 03:39 PM

View PostRonald, on 20 May 2014 - 04:00 PM, said:

@webweaver,

I've worked out a way to add a "buy" button to a WordPress non exchange post or page via a shortcode. It is fairly experimental, some content is hard-coded, but if you want to give it a spin, please do. So this is not an official iThemes Exchange customisation yet.

The assumption is that you know the product ID, and that most other product information will be added in the post. So (currently) it only outputs description, price and the buy now button. In order for this to make sense, it is highly recommended that you add the superwidget to a sidebar, so that the checkout function can be initiated as well. Otherwise, the buy button would be kinda lost.

This is (as far as I'm concerned) still work in progress, but I'm curious to see how/if at all this works for you.

Add the following code at the end of your child theme's functions.php:

/**
* Creates a shortcode to add a product to the cart
*
*/
function my_it_exchange_add_to_cart($atts) {

extract(shortcode_atts(array(
		 "product_id" => null
), $atts));

it_exchange_set_product( $product_id );

$output = "<div class='my_it_itemdescription'>Item: " . it_exchange( 'product', 'get-description' ) . "</div>";
$output .= "<div class='my_it_price'>Price: " . it_exchange( 'product', 'get-base-price' ) . "</div>";
$output .= "<div class='my_it_buy-now'>" .it_exchange( 'product', 'get-purchase-options', array( 'add-to-cart-edit-quantity' => true, 'buy-now-edit-quantity' =>true ) ) . "</div>";

return $output;
}
add_shortcode( 'add-to-cart', 'my_it_exchange_add_to_cart' );

Then add the following shortcode in your post or page:

[add-to-cart product_id=123]

where 123 is the (WordPress) ID of the product,

Ronald
Hi Ronald... this is great help for me. However, I have couple questions.... How do I get rid of the word "item" above the product.... Page is http://alibixclothing.com
Also, any advice on how to change the color of the buy now and add to cart buttons?

Thanks so much.

Robertsing

Posted 18 September 2014 - 02:08 AM

I tried adding to my child theme as describes.

Leaves me with a blank white site. everything gone.

i started from scratch with a trivial theme and no additions in the child except the noted functions.php code.

Ronald

Posted 01 September 2014 - 01:36 PM

Hi Graham,

setting the "buy now edit quantity" bit to false should do the trick, but I've not tested that. Give that a try and let us know,

Ronald

brandstaruk

Posted 27 August 2014 - 06:38 AM

Hi All,

I hope it is ok to ask a question re the code suggested above here as opposed to creating a new post.  

The get-purchase-options in the line of code
$output .= "<div class='my_it_buy-now'>" .it_exchange( 'product', 'get-purchase-options', array( 'add-to-cart-edit-quantity' => true, 'buy-now-edit-quantity' =>true ) ) . "</div></div>";
   return $output;
Is there a way to limit that to just show Add to Cart?

Many thanks,

Graham

Ronald

Posted 18 June 2014 - 03:33 PM

excellent!

Arlen Nagata

Posted 18 June 2014 - 02:41 PM

Building on Ronald's code, Here's what I came up with so far. Although I am very new at working with this API.  

This adds a Featured Thumbnail Image, Product Title and basic tags which can be styled.  

/*
* Creates a shortcode to add a product to the cart
*
*/
function my_it_exchange_add_to_cart($atts) {
   extract(shortcode_atts(array(
						"product_id" => null
   ), $atts));
   it_exchange_set_product( $product_id );
	 $output = "<div class='my_it_product_shortcode'><div class='my_it_itemimage'>" . it_exchange( 'product', 'featured-image', array( 'size' => 'thumbnail', 'return' => 'true' ) ) . "</div>";
		$output .= "<div class='my_it_itemdtitle'><h2>" . it_exchange( 'product', 'get-title' ) . "</h2></div>";
		$output .= "<div class='my_it_itemdescription'><b>Description: </b> " . it_exchange( 'product', 'get-description' ) . "</div>";
		$output .= "<div class='my_it_price'>Price: " . it_exchange( 'product', 'get-base-price' ) . "</div>";
		$output .= "<div class='my_it_buy-now'>" .it_exchange( 'product', 'get-purchase-options', array( 'add-to-cart-edit-quantity' => true, 'buy-now-edit-quantity' =>true ) ) . "</div></div>";
   return $output;
}
add_shortcode( 'add-to-cart', 'my_it_exchange_add_to_cart' );

Review the complete topic (launches new window)