• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / edd_set_cart_discount() – Set the active discount for the shopping cart

You appear to be a bot. Output may be restricted

Description

Set the active discount for the shopping cart

Usage

$string[] = edd_set_cart_discount( $code );

Parameters

$code
( string ) optional – Discount code

Returns

string[] All currently active discounts

Source

File name: easy-digital-downloads/includes/discount-functions.php
Lines:

1 to 27 of 27
function edd_set_cart_discount( $code = '' ) {

  if( edd_multiple_discounts_allowed() ) {
    // Get all active cart discounts
    $discounts = edd_get_cart_discounts();
  } else {
    $discounts = false; // Only one discount allowed per purchase, so override any existing
  }

  if ( $discounts ) {
    $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
    if( false !== $key ) {
      unset( $discounts[ $key ] ); // Can't set the same discount more than once
    }
    $discounts[] = $code;
  } else {
    $discounts = array();
    $discounts[] = $code;
  }

  EDD()->session->set( 'cart_discounts', implode( '|', $discounts ) );

  do_action( 'edd_cart_discount_set', $code, $discounts );
  do_action( 'edd_cart_discounts_updated', $discounts );

  return $discounts;
}
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 26th November 2019

Primary Sidebar

Information

Function name: edd_set_cart_discount
Plugin ref: Easy Digital Downloads
Version: 2.11.6
Sourcefile: includes/discount-functions.php
File ref: includes/discount-functions.php
Deprecated?: No
API Letters: C,D,E,S

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.9.3
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2022. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites