/** * Get Cart Item Template * * @since 1.0 * @param int $cart_key Cart key * @param array $item Cart item * @param bool $ajax AJAX? * @return string Cart item */ function edd_get_cart_item_template($cart_key, $item, $ajax = false) { global $post; $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); if (!empty($options)) { $title .= edd_has_variable_prices($item['id']) ? ' <span class="edd-cart-item-separator">-</span> ' . edd_get_price_name($id, $item['options']) : edd_get_price_name($id, $item['options']); } ob_start(); edd_get_template_part('widget', 'cart-item'); $item = ob_get_clean(); $item = str_replace('{item_title}', $title, $item); $item = str_replace('{item_amount}', edd_currency_filter(edd_format_amount($price)), $item); $item = str_replace('{cart_item_id}', absint($cart_key), $item); $item = str_replace('{item_id}', absint($id), $item); $item = str_replace('{item_quantity}', absint($quantity), $item); $item = str_replace('{remove_url}', $remove_url, $item); $subtotal = ''; if ($ajax) { $subtotal = edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())); } $item = str_replace('{subtotal}', $subtotal, $item); return apply_filters('edd_cart_item', $item, $id); }
/** * Retrieve the Cart Content Details * * Includes prices, tax, etc of all items. * * @since 1.0 * @return array $details Cart content details */ function edd_get_cart_content_details() { global $edd_is_last_cart_item, $edd_flat_discount_total; $cart_items = edd_get_cart_contents(); if (empty($cart_items)) { return false; } $details = array(); $length = count($cart_items) - 1; foreach ($cart_items as $key => $item) { if ($key >= $length) { $edd_is_last_cart_item = true; } $item['quantity'] = edd_item_quantities_enabled() ? absint($item['quantity']) : 1; $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : NULL; $item_price = edd_get_cart_item_price($item['id'], $item['options']); $discount = edd_get_cart_item_discount_amount($item); $discount = apply_filters('edd_get_cart_content_details_item_discount_amount', $discount, $item); $quantity = edd_get_cart_item_quantity($item['id'], $item['options']); $fees = edd_get_cart_fees('fee', $item['id'], $price_id); $subtotal = $item_price * $quantity; foreach ($fees as $fee) { if ($fee['amount'] < 0) { $subtotal += $fee['amount']; } } $tax = edd_get_cart_item_tax($item['id'], $item['options'], $subtotal - $discount); if (edd_prices_include_tax()) { $subtotal -= round($tax, edd_currency_decimal_filter()); } $total = $subtotal - $discount + $tax; // Do not allow totals to go negative if ($total < 0) { $total = 0; } $details[$key] = array('name' => get_the_title($item['id']), 'id' => $item['id'], 'item_number' => $item, 'item_price' => round($item_price, edd_currency_decimal_filter()), 'quantity' => $quantity, 'discount' => round($discount, edd_currency_decimal_filter()), 'subtotal' => round($subtotal, edd_currency_decimal_filter()), 'tax' => round($tax, edd_currency_decimal_filter()), 'fees' => $fees, 'price' => round($total, edd_currency_decimal_filter())); if ($edd_is_last_cart_item) { $edd_is_last_cart_item = false; $edd_flat_discount_total = 0.0; } } return $details; }
/** * Retrieve the Cart Content Details * * Includes prices, tax, etc of all items. * * @since 1.0 * @return array $details Cart content details */ function edd_get_cart_content_details() { $cart_items = edd_get_cart_contents(); if (empty($cart_items)) { return false; } $details = array(); foreach ($cart_items as $key => $item) { $item['quantity'] = edd_item_quantities_enabled() ? absint($item['quantity']) : 1; $item_price = edd_get_cart_item_price($item['id'], $item['options']); $discount = apply_filters('edd_get_cart_content_details_item_discount_amount', edd_get_cart_item_discount_amount($item), $item); $quantity = edd_get_cart_item_quantity($item['id'], $item['options']); $fees = edd_get_cart_fees('fee', $item['id']); $subtotal = $item_price * $quantity - $discount; $tax = edd_get_cart_item_tax($item['id'], $item['options'], $subtotal); if (edd_prices_include_tax()) { $subtotal -= $tax; } $total = round($subtotal + $tax, edd_currency_decimal_filter()); $details[$key] = array('name' => get_the_title($item['id']), 'id' => $item['id'], 'item_number' => $item, 'item_price' => round($item_price, edd_currency_decimal_filter()), 'quantity' => $quantity, 'discount' => round($discount, edd_currency_decimal_filter()), 'subtotal' => round($subtotal, edd_currency_decimal_filter()), 'tax' => round($tax, edd_currency_decimal_filter()), 'fees' => $fees, 'price' => $total); } return $details; }
/** * Calculate Points using cartdata * * Handles to calculate points using cartdata * and return * * @package Easy Digital Downloads - Points and Rewards * @since 1.0.0 **/ public function edd_points_get_user_checkout_points($cartdata, $discount = 0) { global $edd_options; //initial total points $totalpoints = 0; //check conversion rate & points for earning should not empty & cartdata should not empty if (!empty($cartdata)) { foreach ($cartdata as $key => $item) { //check item of options set then consider that if (isset($item['options'])) { $itemoptions = $item['options']; } elseif (isset($item['item_number']['options'])) { $itemoptions = $item['item_number']['options']; } else { $itemoptions = array(); } //get individual points for the item on checkout page $points = $this->edd_points_get_earning_points($item['id'], $itemoptions, true); //calculate total points for item in cart $itemtotalpoints = !empty($points) ? $points * edd_get_cart_item_quantity($item['id']) : 0; //increase total points $totalpoints += $itemtotalpoints; } //end foreach loop if (!empty($discount)) { $totalpointsdiscountgot = $discount; } else { //get discount got by user via points $gotdiscount = EDD()->fees->get_fee('points_redeem'); $totalpointsdiscountgot = !empty($gotdiscount) ? abs($gotdiscount['amount']) : 0; } // reduce by any discounts. One minor drawback: if the discount includes a discount on tax and/or shipping //it will cost the customer points, but this is a better solution than granting full points for discounted orders $totalpoints -= min($this->edd_points_calculate_earn_points_from_price($totalpointsdiscountgot), $totalpoints); } //end if to check conversion points & rate should not empty //return total points user will get return intval($totalpoints); }
<td class="edd_cart_item_price"><?php echo edd_cart_item_price($item['id'], $item['options']); ?> </td> <td class="edd_cart_actions form-inline"> <?php if (edd_item_quantities_enabled()) { ?> <input type="number" min="1" step="1" name="edd-cart-download-<?php echo $key; ?> -quantity" data-key="<?php echo $key; ?> " class="form-control edd-input edd-item-quantity" value="<?php echo edd_get_cart_item_quantity($item['id'], $item['options']); ?> "/> <input type="hidden" name="edd-cart-downloads[]" value="<?php echo $item['id']; ?> "/> <input type="hidden" name="edd-cart-download-<?php echo $key; ?> -options" value="<?php echo esc_attr(serialize($item['options'])); ?> "/> <?php }
/** * Handles the process of adding a ticket product to the cart. * * If the cart already contains a line item for the same product, simply increment the * quantity for that item accordingly. * * @see bug #28917 * @param $product_id * @param $quantity */ protected function add_ticket_to_cart($product_id, $quantity) { // Is the item in the cart already? Simply adjust the quantity if so if (edd_item_in_cart($product_id)) { $existing_quantity = edd_get_cart_item_quantity($product_id); $quantity += $existing_quantity; edd_set_cart_item_quantity($product_id, $quantity); } else { $options = array('quantity' => $quantity); edd_add_to_cart($product_id, $options); } }
echo edd_get_cart_item_quantity($item['id'], $item['options']); ?> " /> <input type="hidden" name="edd-cart-downloads[]" value="<?php echo $item['id']; ?> " /> <input type="hidden" name="edd-cart-download-<?php echo $template_args['key']; ?> -options" value="<?php echo esc_attr(serialize($item['options'])); ?> " /> </label> <?php } ?> </div> <div class="checkout__price one-seventh medium-one-half small-one-fifth"> <?php echo esc_html(edd_currency_filter(edd_format_amount(edd_get_cart_item_price($item['id'], $item['options']) * edd_get_cart_item_quantity($item['id'], $item['options'])))); ?> <a href="<?php echo esc_url(edd_remove_item_url($template_args['key'])); ?> " class="button--naked checkout__cancel edd_cart_remove_item_btn"><span class="text-icon"></a> </div> </li> <?php
if ( ! empty( $item['options'] ) && edd_has_variable_prices( $item['id'] ) ) { $item_title .= ' - ' . edd_get_cart_item_price_name( $item ); } echo '<span class="edd_checkout_cart_item_title">' . esc_html( $item_title ) . '</span>'; do_action( 'edd_checkout_cart_item_title_after', $item ); ?> </td> <td class="edd_cart_item_price"> <?php echo edd_cart_item_price( $item['id'], $item['options'] ); do_action( 'edd_checkout_cart_item_price_after', $item ); ?> </td> <td class="edd_cart_actions"> <?php if( edd_item_quantities_enabled() ) : ?> <input type="number" min="1" step="1" name="edd-cart-download-<?php echo $key; ?>-quantity" data-key="<?php echo $key; ?>" class="edd-input edd-item-quantity" value="<?php echo edd_get_cart_item_quantity( $item['id'], $item['options'] ); ?>"/> <input type="hidden" name="edd-cart-downloads[]" value="<?php echo $item['id']; ?>"/> <input type="hidden" name="edd-cart-download-<?php echo $key; ?>-options" value="<?php echo esc_attr( serialize( $item['options'] ) ); ?>"/> <?php endif; ?> <?php do_action( 'edd_cart_actions', $item, $key ); ?> <a class="edd_cart_remove_item_btn" href="<?php echo esc_url( edd_remove_item_url( $key ) ); ?>"><?php _e( 'Remove', 'edd' ); ?></a> </td> <?php do_action( 'edd_checkout_table_body_last', $item ); ?> </tr> <?php endforeach; ?> <?php endif; ?> <?php do_action( 'edd_cart_items_middle' ); ?> <!-- Show any cart fees, both positive and negative fees --> <?php if( edd_cart_has_fees() ) : ?> <?php foreach( edd_get_cart_fees() as $fee_id => $fee ) : ?> <tr class="edd_cart_fee" id="edd_cart_fee_<?php echo $fee_id; ?>">
/** * Ensure cart quantities are OK * * @since 1.0.0 * @return void */ function edd_pl_checkout_errors($valid_data, $posted) { global $edd_prices_sold_out; $cart = edd_get_cart_contents(); $scope = edd_get_option('edd_purchase_limit_scope') ? edd_get_option('edd_purchase_limit_scope') : 'site-wide'; $errors = array(); foreach ($cart as $item) { if (edd_has_variable_prices($item['id'])) { if (edd_pl_is_item_sold_out($item['id'], $item['options']['price_id'], false, false)) { $errors[] = array('id' => $item['id'], 'price' => $item['options']['price_id'], 'type' => 'soldout', 'avail' => null); } } else { $max_purchases = edd_pl_get_file_purchase_limit($item['id']); if ($scope == 'site-wide') { $purchases = edd_get_download_sales_stats($item['id']); if ($max_purchases && $purchases >= $max_purchases || !empty($edd_prices_sold_out)) { $errors[] = array('id' => $item['id'], 'price' => null, 'type' => 'soldout', 'avail' => null); } } else { if (is_user_logged_in()) { $purchases = edd_pl_get_user_purchase_count(get_current_user_id(), $item['id']); if ($max_purchases && $purchases >= $max_purchases || !empty($edd_prices_sold_out)) { $errors[] = array('id' => $item['id'], 'price' => null, 'type' => 'soldout', 'avail' => null); } } } } if (edd_item_in_cart($item['id'])) { if (edd_has_variable_prices($item['id'])) { $max_purchases = edd_pl_get_file_purchase_limit($item['id'], null, $item['options']['price_id']); $purchases = edd_pl_get_file_purchases($item['id'], $item['options']['price_id']); } if ($max_purchases > 0) { $cart_qty = edd_get_cart_item_quantity($item['id']); $total = $purchases + $cart_qty; if ($total > $max_purchases) { $errors[] = array('id' => $item['id'], 'price' => edd_has_variable_prices($item['id']) ? $item['options']['price_id'] : null, 'type' => 'toomany', 'avail' => $max_purchases - $purchases); } } } } if (count($errors) > 0) { foreach ($errors as $error) { $product = get_post($error['id']); if ($error['type'] == 'soldout') { edd_set_error('purchase_limit_reached', sprintf(__('The %s "%s" is sold out!', 'edd-purchase-limit'), strtolower(edd_get_label_singular()), $product->post_title)); } elseif ($error['type'] == 'toomany') { edd_set_error('purchase_limit_exceeded', sprintf(_n('There is only %s available for the %s "%s"!', 'There are only %s available for the %s "%s"!', $error['avail'], 'edd-purchase-limit'), $error['avail'], strtolower(edd_get_label_singular()), $product->post_title)); } } } }