Welcome to the second part of the series on Easy Digital Downloads and comments customization. In this part we’ll go over restricting comments ( viewing and submission ) based on whether the visitor is a customer or not. Custom “has user purchased” Function Easy Digital Downloads comes with a function called edd_has_user_purchased() but we can’t just call that function in it’s pure form because: If EDD is not enabled it will trigger a PHP error It does not have a default for the user id It does not have a default for post id ( download id ) So we would need to do extra checks every time we use that function. Instead we’ll create a custom function that combines everything, so we can simply call it like this: And here’s what that new function looks like: 1234567891011121314151617181920212223242526 function myprefix_has_user_purchased( $user_id = false, $post_id = false ) {// if function does not exists just return falseif ( ! function_exists( 'edd_has_user_purchased' ) ) {return false;}// if user ID not supplied and current visitor not logged in, return falseif ( ! $user_id && ! is_user_logged_in() ) {return false;}// if user id not supplied
Share This