Skip to content

Instantly share code, notes, and snippets.

@SeanTOSCD
Created June 24, 2014 22:30
Show Gist options
  • Save SeanTOSCD/0ff06e6d0592c5078480 to your computer and use it in GitHub Desktop.
Save SeanTOSCD/0ff06e6d0592c5078480 to your computer and use it in GitHub Desktop.
prevent two recurring paymeny items from being added to EDD cart
<?php
function check_for_only_one_subscription_purchase_at_a_time( $item ) {
$cart_items = edd_get_cart_contents();
if ( $cart_items ) {
$a = array_values( $item );
foreach ( $a as $k => $v ) {
if ( is_array( $v ) ) {
if ( in_array( "recurring", array_keys( $v ) ) ) {
$item_is_recurring_product = TRUE;
}
}
}
foreach ( $cart_items as $key => $value ) {
$a = array_values( $value );
foreach ( $a as $k => $v ) {
if ( is_array( $v ) ) {
if ( in_array( "recurring", array_keys( $v ) ) ) {
$recurring_product_in_cart = TRUE;
}
}
}
}
}
if ( $item_is_recurring_product || $recurring_product_in_cart ) {
wp_die( __( 'Sorry, you cannot purchase a subscription with another item in the same checkout session.', 'edd' ) );
}
return $item;
}
add_filter( 'edd_add_to_cart_item', 'check_for_only_one_subscription_purchase_at_a_time' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment