本文整理汇总了PHP中edd_add_to_cart函数的典型用法代码示例。如果您正苦于以下问题:PHP edd_add_to_cart函数的具体用法?PHP edd_add_to_cart怎么用?PHP edd_add_to_cart使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了edd_add_to_cart函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edd_process_add_to_cart
/**
* Process the Add to Cart request
*
* @since 1.0
*
* @param $data
*/
function edd_process_add_to_cart($data)
{
$download_id = absint($data['download_id']);
$options = isset($data['edd_options']) ? $data['edd_options'] : array();
if (!empty($data['edd_download_quantity'])) {
$options['quantity'] = absint($data['edd_download_quantity']);
}
if (isset($options['price_id']) && is_array($options['price_id'])) {
foreach ($options['price_id'] as $key => $price_id) {
$options['quantity'][$key] = isset($data['edd_download_quantity_' . $price_id]) ? absint($data['edd_download_quantity_' . $price_id]) : 1;
}
}
$cart = edd_add_to_cart($download_id, $options);
if (edd_straight_to_checkout() && !edd_is_checkout()) {
$query_args = remove_query_arg(array('edd_action', 'download_id', 'edd_options'));
$query_part = strpos($query_args, "?");
$url_parameters = '';
if (false !== $query_part) {
$url_parameters = substr($query_args, $query_part);
}
wp_redirect(edd_get_checkout_uri() . $url_parameters, 303);
edd_die();
} else {
wp_redirect(remove_query_arg(array('edd_action', 'download_id', 'edd_options')));
edd_die();
}
}
示例2: edd_ajax_add_to_cart
/**
* Adds item to the cart via AJAX.
*
* @since 1.0
* @return void
*/
function edd_ajax_add_to_cart()
{
if (isset($_POST['download_id']) && check_ajax_referer('edd_ajax_nonce', 'nonce')) {
global $post;
$to_add = array();
if (isset($_POST['price_ids']) && is_array($_POST['price_ids'])) {
foreach ($_POST['price_ids'] as $price) {
$to_add[] = array('price_id' => $price);
}
}
foreach ($to_add as $options) {
if (!edd_item_in_cart($_POST['download_id'], $options)) {
if ($_POST['download_id'] == $options['price_id']) {
$options = array();
}
$key = edd_add_to_cart($_POST['download_id'], $options);
$item = array('id' => $_POST['download_id'], 'options' => $options);
$item = apply_filters('edd_ajax_pre_cart_item_template', $item);
$cart_item = edd_get_cart_item_template($key, $item, true);
echo $cart_item;
} else {
echo 'incart';
}
}
}
edd_die();
}
示例3: edd_ajax_add_to_cart_from_wish_list
/**
* Adds item to the cart from the wish list via AJAX. Based off edd_ajax_add_to_cart()
*
* @since 1.0
* @return void
*/
function edd_ajax_add_to_cart_from_wish_list()
{
if (isset($_POST['download_id'])) {
global $post;
$to_add = array();
if (isset($_POST['price_ids']) && is_array($_POST['price_ids'])) {
foreach ($_POST['price_ids'] as $price) {
$to_add[] = array('price_id' => $price);
}
}
foreach ($to_add as $options) {
if ($_POST['download_id'] == $options['price_id']) {
$options = array();
}
parse_str($_POST['post_data'], $post_data);
if (isset($options['price_id']) && isset($post_data['edd_download_quantity_' . $options['price_id']])) {
$options['quantity'] = absint($post_data['edd_download_quantity_' . $options['price_id']]);
} else {
$options['quantity'] = isset($post_data['edd_download_quantity']) ? absint($post_data['edd_download_quantity']) : 1;
}
// call EDD's edd_add_to_cart function
$key = edd_add_to_cart($_POST['download_id'], $options);
$item = array('id' => $_POST['download_id'], 'options' => $options);
$item = apply_filters('edd_wl_ajax_pre_cart_item_template', $item);
$return = array('add_to_cart' => 'Added to Cart', 'subtotal' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())), ENT_COMPAT, 'UTF-8'), 'cart_item' => html_entity_decode(edd_get_cart_item_template($key, $item, true), ENT_COMPAT, 'UTF-8'));
echo json_encode($return);
}
}
edd_die();
}
示例4: edd_process_add_to_cart
/**
* Process the Add to Cart request
*
* @since 1.0
* @return void
*/
function edd_process_add_to_cart($data)
{
$download_id = $data['download_id'];
$options = isset($data['edd_options']) ? $data['edd_options'] : array();
$cart = edd_add_to_cart($download_id, $options);
if (edd_straight_to_checkout() && !edd_is_checkout()) {
wp_redirect(edd_get_checkout_uri(), 303);
edd_die();
}
}
示例5: edd_process_add_to_cart
/**
* Process the Add to Cart request
*
* @since 1.0
*
* @param $data
*/
function edd_process_add_to_cart( $data ) {
$download_id = absint( $data['download_id'] );
$options = isset( $data['edd_options'] ) ? $data['edd_options'] : array();
$cart = edd_add_to_cart( $download_id, $options );
if ( edd_straight_to_checkout() && ! edd_is_checkout() ) {
wp_redirect( edd_get_checkout_uri(), 303 );
edd_die();
} else {
wp_redirect( remove_query_arg( array( 'edd_action', 'download_id', 'edd_options' ) ) ); edd_die();
}
}
示例6: update_variation
/**
* Updates a product variation to a different one
*/
public function update_variation()
{
$download_id = filter_input(INPUT_POST, 'download_id');
$price_id = filter_input(INPUT_POST, 'price_id');
if (false === $download_id || false === $price_id) {
echo wp_json_encode(['status' => 'error', 'error' => 'No download_id and price_id provided.']);
wp_die();
}
$old_download = edd_get_item_position_in_cart($download_id);
// Add first, then remove, to keep discount codes that might apply.
edd_add_to_cart($download_id, array('price_id' => $price_id));
edd_remove_from_cart($old_download);
echo wp_json_encode(['status' => 'success']);
wp_die();
}
示例7: edd_ajax_add_to_cart
/**
* AJAX Add To Cart
*
* Adds item to the cart.
*
* @access private
* @since 1.0
* @return string
*/
function edd_ajax_add_to_cart()
{
if (isset($_POST['download_id']) && check_ajax_referer('edd_ajax_nonce', 'nonce')) {
global $post;
if (!edd_item_in_cart($_POST['download_id'])) {
$options = is_numeric($_POST['price_id']) ? array('price_id' => $_POST['price_id']) : array();
$key = edd_add_to_cart($_POST['download_id'], $options);
$item = array('id' => $_POST['download_id'], 'options' => $options);
$cart_item = edd_get_cart_item_template($key, $item, true);
echo $cart_item;
} else {
echo 'incart';
}
}
die;
}
示例8: edd_process_add_to_cart
/**
* Process the Add to Cart request
*
* @since 1.0
*
* @param $data
*/
function edd_process_add_to_cart($data)
{
$download_id = absint($data['download_id']);
$options = isset($data['edd_options']) ? $data['edd_options'] : array();
if (!empty($data['edd_download_quantity'])) {
$options['quantity'] = absint($data['edd_download_quantity']);
}
if (is_array($options['price_id'])) {
foreach ($options['price_id'] as $key => $price_id) {
$options['quantity'][$key] = absint($data['edd_download_quantity_' . $price_id]);
}
}
$cart = edd_add_to_cart($download_id, $options);
if (edd_straight_to_checkout() && !edd_is_checkout()) {
wp_redirect(edd_get_checkout_uri(), 303);
edd_die();
} else {
wp_redirect(remove_query_arg(array('edd_action', 'download_id', 'edd_options')));
edd_die();
}
}
示例9: edd_ajax_add_to_cart
/**
* Adds item to the cart via AJAX.
*
* @since 1.0
* @return void
*/
function edd_ajax_add_to_cart()
{
if (isset($_POST['download_id'])) {
$to_add = array();
if (isset($_POST['price_ids']) && is_array($_POST['price_ids'])) {
foreach ($_POST['price_ids'] as $price) {
$to_add[] = array('price_id' => $price);
}
}
$items = '';
foreach ($to_add as $options) {
if ($_POST['download_id'] == $options['price_id']) {
$options = array();
}
parse_str($_POST['post_data'], $post_data);
if (isset($options['price_id']) && isset($post_data['edd_download_quantity_' . $options['price_id']])) {
$options['quantity'] = absint($post_data['edd_download_quantity_' . $options['price_id']]);
} else {
$options['quantity'] = isset($post_data['edd_download_quantity']) ? absint($post_data['edd_download_quantity']) : 1;
}
$key = edd_add_to_cart($_POST['download_id'], $options);
$item = array('id' => $_POST['download_id'], 'options' => $options);
$item = apply_filters('edd_ajax_pre_cart_item_template', $item);
$items .= html_entity_decode(edd_get_cart_item_template($key, $item, true), ENT_COMPAT, 'UTF-8');
}
$return = array('subtotal' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_total())), ENT_COMPAT, 'UTF-8'), 'cart_item' => $items, 'cart_quantity' => html_entity_decode(edd_get_cart_quantity()));
if (edd_use_taxes()) {
$cart_tax = (double) edd_get_cart_tax();
$return['tax'] = html_entity_decode(edd_currency_filter(edd_format_amount($cart_tax)), ENT_COMPAT, 'UTF-8');
}
echo json_encode($return);
}
edd_die();
}
示例10: edd_process_add_to_cart
/**
* Process Add To Cart
*
* Process the add to cart request.
*
* @access private
* @since 1.0
* @return void
*/
function edd_process_add_to_cart($data)
{
$download_id = $data['download_id'];
$options = isset($data['edd_options']) ? $data['edd_options'] : array();
$cart = edd_add_to_cart($download_id, $options);
}
示例11: edd_sl_add_upgrade_to_cart
/**
* Add license upgrade to the cart
*
* @since 3.3
* @return void
*/
function edd_sl_add_upgrade_to_cart($data)
{
if (!is_user_logged_in()) {
return;
}
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'edd_sl_upgrade_nonce')) {
return;
}
$download_id = edd_software_licensing()->get_download_id($data['license_id']);
$cart_contents = edd_get_cart_contents();
$allow_upgrade = true;
if (is_array($cart_contents)) {
foreach ($cart_contents as $item) {
if ($item['id'] == $download_id && !empty($item['options']['is_renewal'])) {
$allow_upgrade = false;
break;
}
}
}
if ('expired' === edd_software_licensing()->get_license_status($data['license_id'])) {
$is_expired = true;
$allow_upgrade = false;
}
if ($allow_upgrade) {
$upgrade = edd_sl_get_upgrade_path($download_id, $data['upgrade_id']);
$options = array('price_id' => $upgrade['price_id'], 'is_upgrade' => true, 'upgrade_id' => $data['upgrade_id'], 'license_id' => $data['license_id'], 'cost' => edd_sl_get_license_upgrade_cost($data['license_id'], $data['upgrade_id']));
edd_add_to_cart($upgrade['download_id'], $options);
} else {
if (!empty($is_expired)) {
edd_set_error('edd-sl-expired-license', __('Your license key is expired. It must be renewed before it can be upgraded.', 'edd_sl'));
} else {
edd_set_error('edd-sl-unique-action', __('Expired license keys cannot be upgraded. Renew your license and then you may upgrade it.', 'edd_sl'));
}
}
wp_redirect(edd_get_checkout_uri());
exit;
}
示例12: edd_add_collection_to_cart
/**
* Add Collection to Cart
*
* Adds all downloads within a taxonomy term to the cart.
*
* @access public
* @since 1.0.6
* @param $taxonomy string - the name of the taxonomy
* @param $terms mixed - the slug or id of the term from which to add ites, or an array of terms
* @return array of IDs for each item added to the cart
*/
function edd_add_collection_to_cart($taxonomy, $terms)
{
if (!is_string($taxonomy)) {
return false;
}
$field = is_int($terms) ? 'id' : 'slug';
$cart_item_ids = array();
$args = array('post_type' => 'download', 'posts_per_page' => -1, $taxonomy => $terms);
$items = get_posts($args);
if ($items) {
foreach ($items as $item) {
edd_add_to_cart($item->ID);
$cart_item_ids[] = $item->ID;
}
}
return $cart_item_ids;
}
示例13: add_ticket_to_cart
/**
* 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);
}
}
示例14: edd_sl_add_renewal_to_cart
/**
* Adds a license key renewal to the cart
*
* @since 3.4
* @param integer $license_id The ID of the license key to add
* @param bool $by_key Set to true if passing actual license key as $license_id
* @return bool|WP_Error $success True if the renewal was added to the cart, WP_Error is not successful
*/
function edd_sl_add_renewal_to_cart($license_id = 0, $by_key = false)
{
if ($by_key) {
$license_key = $license_id;
$license_id = edd_software_licensing()->get_license_by_key($license_id);
} else {
$license_key = edd_software_licensing()->get_license_key($license_id);
}
if (empty($license_id)) {
return new WP_Error('missing_license', __('No license ID supplied or invalid key provided', 'edd_sl'));
}
$license_post = get_post($license_id);
if (!$license_post) {
return new WP_Error('missing_license', __('No license ID supplied or invalid key provided', 'edd_sl'));
}
$success = false;
$payment_id = get_post_meta($license_id, '_edd_sl_payment_id', true);
$payment = get_post($payment_id);
$download_id = edd_software_licensing()->get_download_id($license_id);
$download = get_post($download_id);
if ('publish' !== $payment->post_status && 'complete' !== $payment->post_status) {
return new WP_Error('payment_not_complete', __('The purchase record for this license is not marked as complete', 'edd_sl'));
}
if ('publish' !== $license_post->post_status) {
return new WP_Error('license_disabled', __('The supplied license has been disabled and cannot be renewed', 'edd_sl'));
}
if ('publish' !== $download->post_status) {
return new WP_Error('license_disabled', __('The download for this license is not published', 'edd_sl'));
}
$license_parent = !empty($license_post->post_parent) ? get_post($license_post->post_parent) : false;
// This license key is part of a bundle, setup the parent
if ($license_post->post_parent && !empty($license_parent)) {
$parent_license_id = $license_parent->ID;
$parent_download_id = edd_software_licensing()->get_download_id($parent_license_id);
$parent_license_key = edd_software_licensing()->get_license_key($parent_license_id);
if (!edd_item_in_cart($parent_download_id) && !edd_has_variable_prices($download_id)) {
edd_add_to_cart($parent_download_id);
}
$license_id = $parent_license_id;
$license_key = edd_software_licensing()->get_license_key($parent_license_id);
$license = $parent_license_key;
$download_id = $parent_download_id;
}
$options = array('is_renewal' => true);
// if product has variable prices, find previous used price id and add it to cart
if (edd_has_variable_prices($download_id)) {
$price_id = edd_software_licensing()->get_price_id($license_id);
if ('' === $price_id) {
// If no $price_id is available, try and find it from the payment ID. See https://github.com/pippinsplugins/EDD-Software-Licensing/issues/110
$payment_items = edd_get_payment_meta_downloads($payment_id);
foreach ($payment_items as $payment_item) {
if ((int) $payment_item['id'] !== (int) $download_id) {
continue;
}
if (isset($payment_item['options']['price_id'])) {
$options['price_id'] = $payment_item['options']['price_id'];
break;
}
}
} else {
$options['price_id'] = $price_id;
}
}
if (empty($download_id)) {
return new WP_Error('no_download_id', __('There does not appear to be a download ID attached to this license key', 'edd_sl'));
}
// Make sure it's not already in the cart
$cart_key = edd_get_item_position_in_cart($download_id, $options);
if (edd_item_in_cart($download_id, $options) && false !== $cart_key) {
edd_remove_from_cart($cart_key);
}
edd_add_to_cart($download_id, $options);
$success = true;
// Confirm item was added to cart successfully
if (!edd_item_in_cart($download_id, $options)) {
return new WP_Error('not_in_cart', __('The download for this license is not in the cart or could not be added', 'edd_sl'));
}
// Get updated cart key
$cart_key = edd_get_item_position_in_cart($download_id, $options);
if (true === $success) {
$keys = edd_sl_get_renewal_keys();
$keys[$cart_key] = $license_key;
EDD()->session->set('edd_is_renewal', '1');
EDD()->session->set('edd_renewal_keys', $keys);
return true;
}
return new WP_Error('renewal_error', __('Something went wrong while attempting to apply the renewal', 'edd_sl'));
}
示例15: edd_wl_add_all_to_cart
/**
* Add all items in wish list to the cart
*
* Adds all downloads within a taxonomy term to the cart.
*
* @since 1.0.6
* @param int $list_id ID of the list
* @return array Array of IDs for each item added to the cart
*/
function edd_wl_add_all_to_cart($list_id)
{
$cart_item_ids = array();
$items = edd_wl_get_wish_list($list_id);
if ($items) {
foreach ($items as $item) {
// check that they aren't already in the cart
if (edd_item_in_cart($item['id'], $item['options'])) {
continue;
}
edd_add_to_cart($item['id'], $item['options']);
$cart_item_ids[] = $item['id'];
}
}
}