Created
June 4, 2021 14:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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