本文整理汇总了PHP中edd_get_cart_contents函数的典型用法代码示例。如果您正苦于以下问题:PHP edd_get_cart_contents函数的具体用法?PHP edd_get_cart_contents怎么用?PHP edd_get_cart_contents使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了edd_get_cart_contents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: huesos_edd_show_header_cart_link
/**
* Show cart link and quantity count in header if the cart has contents.
*
* The ".edd-cart-quantity" class is needed in order for the quantity to be
* updated dynamically via AJAX.
*
* @todo Add cart link to mobile navigation bar.
*
* @since 1.0.0
*/
function huesos_edd_show_header_cart_link()
{
if (!edd_get_cart_contents()) {
return;
}
printf('<p class="cart-quantity"><a class="button" href="%1$s">%2$s (<span class="edd-cart-quantity">%3$s</span>)</a></p>', esc_url(edd_get_checkout_uri()), esc_html__('Cart', 'huesos'), esc_html(edd_get_cart_quantity()));
}
示例2: validate_fields
public function validate_fields($valid_data, $post_data)
{
global $rcp_gifts;
if (!$this->cart_has_gift_product()) {
return;
}
$items = edd_get_cart_contents();
$gifts = $_POST['edd_rcp_gift'];
foreach ($items as $key => $item) {
if (!$rcp_gifts->is_gift_product($item['id'])) {
continue;
}
$email = $gifts[$key]['email'] ? sanitize_text_field($gifts[$key]['email']) : false;
$name = $gifts[$key]['name'] ? sanitize_text_field($gifts[$key]['name']) : false;
if (empty($email)) {
edd_set_error('empty_gift_email_' . $key, __('Please enter an email address for the gift recipient', 'rcp-gifts'));
}
if (empty($name)) {
edd_set_error('empty_gift_name_' . $key, __('Please enter the recipient\'s name', 'rcp-gifts'));
}
if (!is_email($email)) {
edd_set_error('invalid_gift_email_' . $key, __('Please enter a valid email address for the gift recipient', 'rcp-gifts'));
}
}
}
示例3: edd_checkout_form
/**
* Get Checkout Form
*
* @access private
* @since 1.0
* @return string
*/
function edd_checkout_form()
{
global $edd_options, $user_ID, $post;
ob_start();
?>
<?php
if (edd_get_cart_contents()) {
?>
<?php
edd_checkout_cart();
?>
<div id="edd_checkout_form_wrap" class="edd_clearfix">
<?php
do_action('edd_checkout_form_top');
if (edd_show_gateways()) {
do_action('edd_payment_payment_mode_select');
} else {
do_action('edd_purchase_form');
}
do_action('edd_checkout_form_bottom');
?>
</div><!--end #edd_checkout_form_wrap-->
<?php
} else {
do_action('edd_empty_cart');
}
return ob_get_clean();
}
示例4: edd_shopping_cart
/**
* Shopping Cart
*
* @access public
* @since 1.0
* @return string
*/
function edd_shopping_cart($echo = false)
{
global $edd_options;
ob_start();
?>
<?php
do_action('edd_before_cart');
?>
<ul class="edd-cart">
<?php
$cart_items = edd_get_cart_contents();
if ($cart_items) {
foreach ($cart_items as $key => $item) {
echo edd_get_cart_item_template($key, $item, false);
}
echo '<li class="cart_item edd_checkout"><a href="' . get_permalink($edd_options['purchase_page']) . '">' . __('Checkout', 'edd') . '</a></li>';
} else {
echo '<li class="cart_item empty">' . edd_empty_cart_message() . '</li>';
echo '<li class="cart_item edd_checkout" style="display:none;"><a href="' . get_permalink($edd_options['purchase_page']) . '">' . __('Checkout', 'edd') . '</a></li>';
}
?>
</ul>
<?php
do_action('edd_after_cart');
?>
<?php
if ($echo) {
echo ob_get_clean();
} else {
return ob_get_clean();
}
}
示例5: edd_process_purchase_form
/**
* Process Purchase Form
*
* Handles the purchase form process.
*
* @access private
* @since 1.0
* @return void
*/
function edd_process_purchase_form()
{
do_action('edd_pre_process_purchase');
// Make sure the cart isn't empty
if (!edd_get_cart_contents() && !edd_cart_has_fees()) {
$valid_data = false;
edd_set_error('empty_cart', __('Your cart is empty', 'easy-digital-downloads'));
} else {
// Validate the form $_POST data
$valid_data = edd_purchase_form_validate_fields();
// Allow themes and plugins to hook to errors
do_action('edd_checkout_error_checks', $valid_data, $_POST);
}
$is_ajax = isset($_POST['edd_ajax']);
// Process the login form
if (isset($_POST['edd_login_submit'])) {
edd_process_purchase_login();
}
// Validate the user
$user = edd_get_purchase_form_user($valid_data);
if (false === $valid_data || edd_get_errors() || !$user) {
if ($is_ajax) {
do_action('edd_ajax_checkout_errors');
edd_die();
} else {
return false;
}
}
if ($is_ajax) {
echo 'success';
edd_die();
}
// Setup user information
$user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount'], 'address' => $user['address']);
$auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
// Setup purchase information
$purchase_data = array('downloads' => edd_get_cart_contents(), 'fees' => edd_get_cart_fees(), 'subtotal' => edd_get_cart_subtotal(), 'discount' => edd_get_cart_discounted_amount(), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_total(), 'purchase_key' => strtolower(md5($user['user_email'] . date('Y-m-d H:i:s') . $auth_key . uniqid('edd', true))), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s', current_time('timestamp')), 'user_info' => stripslashes_deep($user_info), 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']);
// Add the user data for hooks
$valid_data['user'] = $user;
// Allow themes and plugins to hook before the gateway
do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data);
// If the total amount in the cart is 0, send to the manual gateway. This emulates a free download purchase
if (!$purchase_data['price']) {
// Revert to manual
$purchase_data['gateway'] = 'manual';
$_POST['edd-gateway'] = 'manual';
}
// Allow the purchase data to be modified before it is sent to the gateway
$purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data);
// Setup the data we're storing in the purchase session
$session_data = $purchase_data;
// Make sure credit card numbers are never stored in sessions
unset($session_data['card_info']['card_number']);
// Used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data.
edd_set_purchase_session($session_data);
// Send info to the gateway for payment processing
edd_send_to_gateway($purchase_data['gateway'], $purchase_data);
edd_die();
}
示例6: download_checkout_count_function
function download_checkout_count_function($atts, $content)
{
$cart_items = edd_get_cart_contents();
if (empty($cart_items)) {
return 0;
} else {
return count($cart_items);
}
}
示例7: pw_edd_prevent_duplicate_purchase
/**
* Prevents logged-in customers from purchasing an item twice
*
*/
function pw_edd_prevent_duplicate_purchase($valid_data, $posted)
{
$cart_contents = edd_get_cart_contents();
foreach ($cart_contents as $item) {
if (edd_has_user_purchased(get_current_user_id(), $item['id'])) {
edd_set_error('duplicate_item', 'You have already purchased this item so may not purchase it again');
}
}
}
示例8: empty_cart
public function empty_cart($wp_admin_bar)
{
$title = __('Empty Cart', 'edd-dev-tools');
$count = count(edd_get_cart_contents());
if (!empty($count)) {
$title .= '(' . $count . ')';
}
$args = array('id' => 'edd_empty_cart', 'title' => $title, 'href' => add_query_arg('empty_cart', true));
$wp_admin_bar->add_node($args);
}
示例9: edd_checkout_form
/**
* Get Checkout Form
*
* @since 1.0
* @return string
*/
function edd_checkout_form()
{
$payment_mode = edd_get_chosen_gateway();
$form_action = esc_url(edd_get_checkout_uri('payment-mode=' . $payment_mode));
ob_start();
echo '<div id="edd_checkout_wrap">';
if (edd_get_cart_contents() || edd_cart_has_fees()) {
edd_checkout_cart();
?>
<div id="edd_checkout_form_wrap" class="edd_clearfix">
<?php
do_action('edd_before_purchase_form');
?>
<form id="edd_purchase_form" class="edd_form" action="<?php
echo $form_action;
?>
" method="POST">
<?php
/**
* Hooks in at the top of the checkout form
*
* @since 1.0
*/
do_action('edd_checkout_form_top');
if (edd_show_gateways()) {
do_action('edd_payment_mode_select');
} else {
do_action('edd_purchase_form');
}
/**
* Hooks in at the bottom of the checkout form
*
* @since 1.0
*/
do_action('edd_checkout_form_bottom');
?>
</form>
<?php
do_action('edd_after_purchase_form');
?>
</div><!--end #edd_checkout_form_wrap-->
<?php
} else {
/**
* Fires off when there is nothing in the cart
*
* @since 1.0
*/
do_action('edd_cart_empty');
}
echo '</div><!--end #edd_checkout_wrap-->';
return ob_get_clean();
}
示例10: edd_process_purchase_form
/**
* Process Purchase Form
*
* Handles the purchase form process.
*
* @access private
* @since 1.0
* @version 1.0.8.1
* @return void
*/
function edd_process_purchase_form()
{
// no need to run on admin
if (is_admin()) {
return;
}
// verify the nonce for this action
if (!isset($_POST['edd-nonce']) || !wp_verify_nonce($_POST['edd-nonce'], 'edd-purchase-nonce')) {
return;
}
// make sure the cart isn't empty
$cart = edd_get_cart_contents();
if (empty($cart)) {
wp_die(sprintf(__('Your cart is empty, please return to the %ssite%s and try again.', 'edd'), '<a href="' . esc_url(home_url()) . '" title="' . get_bloginfo('name') . '">', '</a>'), __('Error', 'edd'));
}
// validate the form $_POST data
$valid_data = edd_purchase_form_validate_fields();
// allow themes and plugins to hoook to errors
do_action('edd_checkout_error_checks', $_POST);
// check errors
if (false !== ($errors = edd_get_errors())) {
// we have errors, send back to checkout
edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']);
exit;
}
// check user
if (false === ($user = edd_get_purchase_form_user($valid_data))) {
// something went wrong when collecting data, send back to checkout
edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']);
exit;
}
// setup user information
$user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount']);
// setup purchase information
$purchase_data = array('downloads' => edd_get_cart_contents(), 'subtotal' => edd_get_cart_amount(false), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_amount(), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']);
// add the user data for hooks
$valid_data['user'] = $user;
// allow themes and plugins to hook before the gateway
do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data);
// allow the purchase data to be modified before it is sent to the gateway
$purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data);
// if the total amount in the cart is 0, send to the manaul gateway. This emulates a free download purchase
if ($purchase_data['price'] <= 0) {
// revert to manual
$valid_data['gateway'] = 'manual';
}
// used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data.
edd_set_purchase_session($purchase_data);
// send info to the gateway for payment processing
edd_send_to_gateway($valid_data['gateway'], $purchase_data);
exit;
}
示例11: pw_edd_recurring_limit_one_subscription
function pw_edd_recurring_limit_one_subscription($valid_data, $post_data)
{
if (!class_exists('EDD_Recurring_Customer')) {
return;
}
if (!is_user_logged_in()) {
return;
}
$purchase_data = array('downloads' => edd_get_cart_contents());
if (EDD_Recurring_Customer::is_customer_active() && EDD_Recurring()->is_purchase_recurring($purchase_data)) {
edd_set_error('edd-one-subscription', __('You already have an active subscription so may not purchase a second one.', 'edd'));
}
}
示例12: edd_process_purchase_form
/**
* Process Purchase Form
*
* Handles the purchase form process.
*
* @access private
* @since 1.0
* @version 1.0.8.1
* @return void
*/
function edd_process_purchase_form()
{
global $edd_options;
// no need to run on admin
if (is_admin()) {
return;
}
// verify the nonce for this action
if (!isset($_POST['edd-nonce']) || !wp_verify_nonce($_POST['edd-nonce'], 'edd-purchase-nonce')) {
return;
}
// validate the form $_POST data
$valid_data = edd_purchase_form_validate_fields();
// allow themes and plugins to hoook to errors
do_action('edd_checkout_error_checks', $_POST);
// check errors
if (false !== ($errors = edd_get_errors())) {
// we have errors, send back to checkout
edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']);
exit;
}
// check user
if (false === ($user = edd_get_purchase_form_user($valid_data))) {
// something went wrong when collecting data, send back to checkout
edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']);
exit;
}
// setup user information
$user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount']);
// setup purchase information
$purchase_data = array('downloads' => edd_get_cart_contents(), 'price' => edd_get_cart_amount(), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']);
// add the user data for hooks
$valid_data['user'] = $user;
// allow themes and plugins to hook before the gateway
do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data);
// allow the purchase data to be modified before it is sent to the gateway
$purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data);
// if the total amount in the cart is 0, send to the manaul gateway. This emulates a free download purchase
if ($purchase_data['price'] <= 0) {
// revert to manual
$valid_data['gateway'] = 'manual';
}
if (isset($edd_options['show_links_on_success'])) {
// used for showing download links to non logged-in users after purchase
edd_set_purchase_session($purchase_data);
}
// send info to the gateway for payment processing
edd_send_to_gateway($valid_data['gateway'], $purchase_data);
exit;
}
示例13: atcf_shipping_cart_shipping
/**
* Do any items in the cart require shipping?
*
* @since Astoundify Crowdfunding 0.9
*
* @return void
*/
function atcf_shipping_cart_shipping()
{
$cart_items = edd_get_cart_contents();
$needs = false;
if (!empty($cart_items)) {
foreach ($cart_items as $key => $item) {
$campaign = atcf_get_campaign($item['id']);
if ($campaign->needs_shipping()) {
$needs = true;
}
}
}
return apply_filters('atcf_shipping_cart_shipping', $needs);
}
示例14: edd_process_purchase_form
/**
* Process Purchase Form
*
* Handles the purchase form process.
*
* @access private
* @since 1.0
* @version 1.0.8.1
* @return void
*/
function edd_process_purchase_form()
{
// Make sure the cart isn't empty
if (!edd_get_cart_contents()) {
edd_set_error('empty_cart', __('Your cart is empty', 'edd'));
} else {
// Validate the form $_POST data
$valid_data = edd_purchase_form_validate_fields();
// Allow themes and plugins to hoook to errors
do_action('edd_checkout_error_checks', $valid_data, $_POST);
}
$is_ajax = isset($_POST['edd_ajax']);
$user = edd_get_purchase_form_user($valid_data);
if (edd_get_errors() || !$user) {
if ($is_ajax) {
do_action('edd_ajax_checkout_errors');
edd_die();
} else {
return false;
}
}
if ($is_ajax) {
echo 'success';
edd_die();
}
// Setup user information
$user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount']);
// Setup purchase information
$purchase_data = array('downloads' => edd_get_cart_contents(), 'fees' => edd_get_cart_fees(), 'subtotal' => edd_get_cart_subtotal(), 'discount' => edd_get_cart_discounted_amount(), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_total(), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']);
// Add the user data for hooks
$valid_data['user'] = $user;
// Allow themes and plugins to hook before the gateway
do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data);
// Allow the purchase data to be modified before it is sent to the gateway
$purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data);
// If the total amount in the cart is 0, send to the manaul gateway. This emulates a free download purchase
if (!$purchase_data['price']) {
// Revert to manual
$valid_data['gateway'] = 'manual';
}
// Used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data.
edd_set_purchase_session($purchase_data);
// Send info to the gateway for payment processing
edd_send_to_gateway($valid_data['gateway'], $purchase_data);
edd_die();
}
示例15: marketify_recommended_products
/**
* Add our own output of recommended products, as the plugin
* uses the standard grid by default, and we need our own.
*
* @since Marketify 1.0
*
* @return void
*/
function marketify_recommended_products()
{
global $edd_options;
if (!function_exists('edd_rp_get_suggestions')) {
return;
}
if (is_singular('download')) {
global $post;
$suggestion_data = edd_rp_get_suggestions($post->ID);
} else {
$cart_items = edd_get_cart_contents();
if (empty($cart_items)) {
return;
}
$post_ids = wp_list_pluck($cart_items, 'id');
$user_id = is_user_logged_in() ? get_current_user_id() : false;
$suggestion_data = edd_rp_get_multi_suggestions($post_ids, $user_id);
}
if (!is_array($suggestion_data) || empty($suggestion_data)) {
return;
}
$suggestions = array_keys($suggestion_data);
$suggested_downloads = new WP_Query(array('post__in' => $suggestions, 'post_type' => 'download', 'posts_per_page' => edd_get_option('edd_rp_suggestion_count')));
?>
<h1 class="section-title recommended-products"><span><?php
_e('Recommended Products', 'marketify');
?>
</span></h1>
<div class="row edd-recommended-products">
<?php
while ($suggested_downloads->have_posts()) {
$suggested_downloads->the_post();
?>
<div class="col-lg-3 col-md-4 col-sm-6">
<?php
get_template_part('content-grid', 'download');
?>
</div>
<?php
}
?>
</div>
<?php
}