Jump to content


Replying to Shortcode For Exchange?


Post Options

  or Cancel


Topic Summary

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' );

Arlen Nagata

Posted 18 June 2014 - 02:06 PM

Thanks Ronald!  

This is amazing!  I'm going to work on adding the product image and title and wrapping it in a div for styling.

Ronald

Posted 18 June 2014 - 03:05 AM

Hi Valerie,

the product id is the same as the WordPress post ID. You can find this in the url when you are editing a product for instance, or when you hover over the product in the list of products,

See also: http://codex.wordpress.org/FAQ_Working_with_WordPress#How_do_I_determine_a_Post.2C_Page.2C_Category.2C_Tag.2C_Link.2C_Link_Category.2C_or_User_ID.3F

Ronald

strongeagle

Posted 18 June 2014 - 01:36 AM

This is exciting, Ronald!  I'm going to try this...but...

Where do I find the product ID?

Thanks,

Valerie

Ronald

Posted 20 May 2014 - 04:00 PM

@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

webweaver

Posted 16 May 2014 - 10:21 AM

shortcodes for individual products to be placed on non-shop page would be awesome!

kevinbatdorf

Posted 10 August 2013 - 10:14 AM

Hey Elise,

This is a feature I would really use as well. I would also like to include an add to cart button on the store page, so the customer wont have to load the product page. Is there a way to do this through the API?

I saw this function in the documentation but not sure how populate those variables.

it_exchange_add_cart_product( $cart_product_id, $product );

Review the complete topic (launches new window)