Skip to content

Instantly share code, notes, and snippets.

@amdrew
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amdrew/115ea3bfcfbcac7090cc to your computer and use it in GitHub Desktop.
Save amdrew/115ea3bfcfbcac7090cc to your computer and use it in GitHub Desktop.
Easy Digital Download - Force account creation if a download in cart has a specific download category or tag
<?php
/*
* Plugin Name: Easy Digital Downloads - Force account creation by category or tag
* Description: Forces the customer to create an account at checkout if a download in the cart has a specific download category or tag
* Author: Andrew Munro
* Version: 1.0
*/
function sumobi_edd_force_account_creation_by_download_category_or_tag( $ret ) {
// download categories that the download must belong to before account creation is forced
$categories_to_search = array( 'cat1', 'cat2', 'cat3' );
// download tags that the download must belong to before account creation is forced
$tags_to_search = array( 'tag1', 'tag2' );
// get our cart contents
$cart = edd_get_cart_contents();
if ( $cart ) {
// create an array with all our download IDs
$download_ids = wp_list_pluck( $cart, 'id' );
if ( $download_ids ) {
// loop through IDs and check if they belong to any of the categories or tags
foreach ( $download_ids as $id ) {
if ( has_term( $categories_to_search, 'download_category', $id ) || has_term( $tags_to_search, 'download_tag', $id ) ) {
// found one, force account creation
$ret = (bool) true;
}
}
}
}
return $ret;
}
add_filter( 'edd_no_guest_checkout', 'sumobi_edd_force_account_creation_by_download_category_or_tag' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment