Skip to content

Instantly share code, notes, and snippets.

@Basilakis
Created June 4, 2021 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Basilakis/ce9f88353c9b1a7205968f82c075588a to your computer and use it in GitHub Desktop.
Save Basilakis/ce9f88353c9b1a7205968f82c075588a to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Suppliment shortcode to validate item in the cart and print details
/**
* Suppliment shortcode to validate item in the cart and print details
*/
function cart_content_shortcode( $atts,$cart_key, $item, $ajax = false ) {
global $post;
$cart_contents = edd_get_cart_contents();
if ( ! empty( $cart_contents ) ) {
foreach ( $cart_contents as $item ) {
$id = is_array($item) ? $item['id'] : $item;
$remove_url = edd_remove_item_url($cart_key);
$title = get_the_title($id);
$options = !empty($item['options']) ? $item['options'] : array();
$quantity = edd_get_cart_item_quantity($id, $options);
$price = edd_get_cart_item_price($id, $options);
extract(shortcode_atts(array(
'element' => 'title', //Assigning default value
), $atts));
switch( $element ){
case 'title':
echo $title;
break;
case 'price':
echo $price;
break;
default:
$output = '<div class="defaultshortcodecontent"></div>';
break;
}
return $output;
}
}
}
add_shortcode('cart-content', 'cart_content_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment