Giter Site home page Giter Site logo

edd-library's Introduction

EDD Code Snippet Library

This is a community-maintained repository of code snippets that help modify the default behavior of Easy Digital Downloads.

Snippets are organized into categories (folders) and each snippet is placed in its own file with a name that describes what it does.

View the full site here

Using the full site (link above) instead of browsing this repository is recommended.

Important: Snippets are not actively maintained or supported. Use at your own risk.

edd-library's People

Contributors

amdrew avatar aristath avatar ashleyfae avatar brashrebel avatar chriscct7 avatar christ0ph3r avatar cklosowski avatar dgoldak avatar flowdee avatar garubi avatar michaelbeil avatar mihaijoldis avatar mindctrl avatar mintplugins avatar natewr avatar pderksen avatar pippinsplugins avatar robincornett avatar scottopolis avatar seantoscd avatar toddgeist avatar x-raym avatar zackkatz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

edd-library's Issues

[Snippet Request] forcing a tax rate on a specific cart item

A pretty straightforward request I "think", but wasn't sure how to approach this exactly. The logic would be as follows:

  1. Customer adds various items to the cart and proceeds to checkout.

  2. He/she enters his details and IF one of the countries he selects has tax set, set a specific item in the cart to a forced rate (like 20%) but make sure the other items remain using the tax rate provided by the countries list.

Is this possible?

Add email template tag override for {billing_address} to use full country/state names.

Normally, EDDs {billing_address} template tag uses the country/state shortcodes in the purchase receipt.

For example, if the state was "Alabama" and the country was "United States", it would output "AL, US" instead of the full names. This snippet will remove the normal template tag and replace it with the same tag but a different callback function that outputs the full names.

New FES Snippet for Content-Restricting Vendor data

This will allow Vendors to submit data - like an embedded video - and have it be automatically output into the Product's description wrapped in [edd_restrict] shortcodes. The content will only display for customers who have purchased the product.

All Snippets Should be in Plugin Form

We should make all snippets have full plugin headers. That way users don't need to make them manually if they want to paste it in a file and upload that file as a plugin

Disable renewals/extensions for a specific Download

A customer asked how he can do that and @ashleyfae got this wipped up pretty quick and it works correctly on my test site.

function ag_edd_sl_can_renew( $can_renew, $license_id ) {
	// Bail if they already can't renew.
	if ( ! $can_renew ) {
		return $can_renew;
	}
	$license = edd_software_licensing()->get_license( $license_id );
	if ( ! $license ) {
		return $can_renew;
	}
	$download_id_not_allowed = 123; // Change this
	if ( $license->download_id == $download_id_not_allowed ) {
		$can_renew = false;
	}
	return $can_renew;
}
add_filter( 'edd_sl_can_extend_license', 'ag_edd_sl_can_renew', 10, 2 );
add_filter( 'edd_sl_can_renew_license', 'ag_edd_sl_can_renew', 10, 2 );

[Snippet Request] Commissions withholding tax modification

For new projects going forward I would be interested in seeing some example code/functions demonstrating how to modify the recorded commission amount based on the vendors country of origin and the customers country. In reality, just a basic example to get me going so I can expand on further into a full plugin.

For example the following scenarios:

  1. Customer purchasing is from Sweden and vendor is based in US, in which case commission should have 20% withheld from the gross amount (original item price) (this isn't real data - just an example). The commission amount recorded should be modified based on this.

  2. Ideally another example could be given showing the calculation performed on the commission amount only and not the cart item price.

All Access do not count repeat downloads not working once limit reached

Based on the Slack conversation the scenario is that if you purchase a pass with 1 download/day and you download the file any other download attempts for the same file will hit the limit error as the snippet does not run once the limit is reached.

It works fine if you have say 5 downloads/day and you download the same file over and over but once you download 5 different files you can't redownload them again as the snippet does not run.

Recurring one subscription fatal error

Added the snippet to the functions.php file and checkout breaks,

[10-Nov-2018 12:24:28 UTC] PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function pw_edd_recurring_limit_one_subscription(), 1 passed in D:\MAMP\htdocs\edd\wp-includes\class-wp-hook.php on line 288 and exactly 2 expected in D:\MAMP\htdocs\edd\wp-content\themes\themedd\functions.php:71

i change the add_action and added the params at the end and it seems to work now
add_action( 'edd_checkout_error_checks', 'pw_edd_recurring_limit_one_subscription', 10, 2 );

Also there seems to be throwing lots of deprecated notices

Feature Request: EDD purchase RCP Subscription

I wasn't able to find anything in the custom snippets or in the addons for this feature. I was wondering if it would be possible to allow Easy Digital Downloads to allow an individual to purchase an RCP subscription (in case they are interested in both a subscription & product(s)).

I can't use the EDD_Payment class

I am integrating my website with hotmart, I am creating a payment manually, however, it is not running.

private function generate_payment($obj){
		$payment = new EDD_Payment();
		$payment->add_download( 3678 ); 
		$payment->email = $obj['email'];
		$payment->status = 'complete'; 
		$payment->save(); 
	}

    private function create_user($obj) {
        $obj['password'] = wp_generate_password(6, false);
        if (email_exists($obj["email"])) {
            $user = get_user_by( 'email', $obj["email"] );
            wp_set_password( $obj['password'], $user->ID );
            generate_payment($obj);         
        } else {
            $userdata = array(
                'user_login' => $obj['email'],
                'user_nicename' => $obj['first_name'],
                'first_name' => $obj['first_name'],
                'last_name' => $obj['last_name'],
                'user_email' => $obj['email'],
                'user_pass' => $obj['password'],
            );
            wp_insert_user($userdata);
			generate_payment($obj);
        }

        $this->send_email($obj);        
    }

Would you help me?

Add snippet for customizing All Access categories on the fly

All Access is getting a new filter to allow any Pass to have the attached categories be modified on-the-fly. This would allow you to set specific categories for a specific AA product, affecting all users who have purchased that AA product, or even just a specific customer with a specific AA product.

A snippet example will be added here to show how it can be used.

All Access - add snippet to expire pass when download counter exhausted.

Some customers have requested that All Access have the option to be used more like a credit system, using the download counter as credits.

Currently, once download credits are exhausted, the customer has to wait until their All Access pass expires, so that renewal purchases kick-in and replenish their download limit.

This makes sense if the pass has an expiration date, like 10 downloads per year.

But if you are using All Access as more of a credit system, you might make the All Access Pass never expire, and give the customer 10 downloads total. Once they use up their 10 downloads, you might want them to be able to repurchase so they get 10 more downloads. But since the AA pass is set to never expire, repurchasing the AA pass doesn't actually do anything, as it only serves to extend the term, which is currently infinite.

In this issue I will add a snippet which makes an All Access Pass expire the moment that the download counter is exhausted, even if it is set to Never Expire. This allows the customer to immediately repurchase, replenishing their download limit.

Variable pricing dropdown not working

The Variable Pricing Dropdown snippet is not functioning properly. While it does add a dropdown, it does not remove the original variable pricing options.

Example:
Screenshot_2020-08-13 EDD Test โ€“ Just another WordPress site

Managing Bundles or Packages based on users access

I am setting up EDD for selling a Pro version with add-ons as a bundle i.e A Package.
when user purchases, they will only get a download file for Pro not for add-ons.
So, when they activate the license, then they can Install the add-ons from plugin settings page.
I want to setup these add-ons in EDD along with Pro as a Download. So automatic updates could work for these add-ons as well.
How will One license key work for all these Products i.e Pro and add-ons?

[Snippet Request] Safe way to check if a customer has access to a download

EDD core has the function edd_user_has_purchased() to check if current user has already purchased a download

But there is more checks to see If the site has EDD SL and If user has limit the download and probably there are other conditionals to check based in other plugins

So, how can I check if user has purchased, has an active license and do not have exceed the limit of download times?

I was thinking about this and i do not know If EDD core should include a method (with filters) to check the completely aviability of a download for a customer or this question can be solved adding a note for developers about how to check this aviability

Clean up API request logs daily

Hi EDD team

I was facing issues with an excessive database size caused by the amount of posts and post metas generated by the EDD rest API

For that, I was in the need to create a functionality that cleans up all API requests logs and I want to share it to the EDD development team

The code is safe to run included if you make (finally) the migration of logs on another table since will query directly to database matching posts by post_type

There is the code:

function themedd_child_edd_logs_cleanup_init() {

    // Setup the daily cron event to process events daily
    if ( ! wp_next_scheduled( 'themedd_child_edd_logs_cleanup_process' ) )
        wp_schedule_event( time(), 'daily', 'themedd_child_edd_logs_cleanup_process' );

}
add_action( 'init', 'themedd_child_edd_logs_cleanup_init' );

function themedd_child_edd_logs_cleanup_process() {

    global $wpdb;

    $api_request_term = get_term_by( 'slug', 'api_request', 'edd_log_type' );

    if( ! $api_request_term ) return;

    $term_id = $api_request_term->term_id;

    // Query to remove EDD logs of api requests
    $sql = "DELETE p
    FROM {$wpdb->posts} p
    LEFT JOIN {$wpdb->term_relationships} tr ON p.ID = tr.object_id
    WHERE p.post_type = 'edd_log'
        AND tr.term_taxonomy_id = {$term_id}";

    $wpdb->query( $sql );

    // Query to remove orphaned post metas
    $sql = "DELETE pm
    FROM {$wpdb->postmeta} pm
    LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
    WHERE p.ID IS NULL";

    $wpdb->query( $sql );

    // Query to remove orphaned term relationships
    $sql = "DELETE tr
    FROM {$wpdb->term_relationships} tr
    LEFT JOIN {$wpdb->posts} p ON p.ID = tr.object_id
    WHERE p.ID IS NULL";

    $wpdb->query( $sql );

}
add_action( 'themedd_child_edd_logs_cleanup_process', 'themedd_child_edd_logs_cleanup_process' );

Hope it helps

[Snippet Request] Calculate tax after discounts option

In older EDD releases the option to calculate tax after discounts, with the ability to enable or disable it. Here is a screenshot I found on GitHub:

8b96e6aa-28e8-11e4-9636-5b76555f05f7

Is it possible to re-add this to the EDD (or optionally) on a per product basis?

New snippet to restrict purchases for the same active subscription again

Was requested by a customer that if the user has an active subscription for Download X he should not be allowed to buy it again.
Code that seems to work:

function pw_edd_recurring_limit_one_subscription( $valid_data, $post_data ) {

	if( ! is_user_logged_in() ) {
		return;
	}

	$subscriber = new EDD_Recurring_Subscriber( get_current_user_id(), true );
	$cart_contents = edd_get_cart_contents();

	foreach( $cart_contents as $item ) {
		if( $subscriber->has_active_product_subscription( $item['id'] ) ) {
			edd_set_error( 'duplicate_item', 'You have already purchased this item so may not purchase it again' );
		}
	}

}
add_action( 'edd_checkout_error_checks', 'pw_edd_recurring_limit_one_subscription', 10, 2 );

Translating "Product(s)" in FES

In FES, you can't translate the word "Product(s)" without writing some filter functions. Those should be added to the library (which I will do through this issue).

All Access: Override/Hide file-specific download options

In All Access issue 156, support was added for multiple files per variable price/single price.

screen shot 2017-10-20 at 12 34 39 pm

However, if you do not wish to use this, and you happen to have files with multiple files per price, and you are not able to remove the additional files you wish to hide from your All Access customers, a code snippet will be added here which sets the over-rides the output to hide the files like this:

screen shot 2017-10-20 at 12 34 39 pm

Note that in this case, the first available/attached file for the relevant price will be downloaded by the customer.

The filter which enables this snippet was added to All Access here:
https://github.com/easydigitaldownloads/edd-all-access/issues/195

Adjust commissions cart item price if fees applied to order

As per the new filter (eddc_calc_commission_amount_args) added in Commissions 3.4.4, I have written a code snippet that adjusts the cart item price to take into account any "fees" applied to the order, such as from extensions Discounts Pro and Points & Rewards.

The way fees currently work, mean the store takes the full hit and the commission recipient still receives 50% of the cart item price. Using this sample, the fees are deducted from the cart item price meaning the correct amount is allocated to the vendor.

Will submit PR to go along with this issue.

EDD Checks label

Add function which makes "Checks" into "Wire Transfer" and could be used for anything else as well.

Download count product

I use the All Access plugin
How do I display how many times the product has been downloaded?
I don't want to show sales, I want to show how many times they've downloaded the product.

Move SL gists to the Library

As part of some changes to the Software Licensing samples (showing how to support auto updates), I'm updating the documentation we have on that. There are quite a few gists in there, but I'd like to update them and move them to the Library, partly so I can edit them, and partly to simplify that documentation page a bit.

All Access - only count last download

A store is selling video files. To prevent download timeouts, it's broken the videos into multiple files and attached each chunk to the product as separate files. Because of this, the store only wants the last file attached to each product to count against the download limit. A filter hook is being added to make this possible here: https://github.com/easydigitaldownloads/edd-all-access/issues/178

In this issue I'll add a function which hooks to that to accomplish that.

All Access: Make specific downloads count for more than 1 download "credit"

Though EDD All Access does not work like a credit system, some customers have requested that certain downloads are worth more downloads in the download limiting system. This would allow the download limiting system to work more like a crediting system.

For example, you might want all products to count as 1 download, but a download pack of 10 (in a single zip file) to count as 10 downloads.

I'll add an example snippet here that does this.

Force products number on recommended products extension

Hi

EDD Recommended Products actually tries to search suggestion based on already in cart products

Sometimes it can not find the expected results and the number of given results could be random (sometimes nothing, sometimes two or sometimes four)

this presents a problem for new products or expensive products which are generally sold alone

I fix it on my site forcing the number of recommendations always to the configured adding random products

Here is my code:

add_filter('edd_rp_multi_recommendation_results', 'force_recommendation_results');
function force_recommendation_results( $suggestions ) {
    if(count($suggestions) < edd_get_option( 'edd_rp_suggestion_count', 3 )) {
        $max_results = edd_get_option( 'edd_rp_suggestion_count', 3 ) - count($suggestions);

        // Excludes cart items and already suggested downloads
        $cart_items = edd_get_cart_contents();
        $cart_post_ids = array_map('intval', wp_list_pluck( $cart_items, 'id' ));

        $excluded_downloads = array_merge( $cart_post_ids, array_keys( $suggestions ) );

        // Excludes already purchased downloads
        $user_purchases = edd_get_users_purchases( get_current_user_id(), -1, false, 'any' );

        if($user_purchases) {
            foreach($user_purchases as $user_purchase) {
                $purchase_downloads = edd_get_payment_meta_cart_details( $user_purchase->ID, true );

                foreach($purchase_downloads as $purchase_download) {
                    $excluded_downloads[] = $purchase_download['id'];
                }
            }
        }

        $random_suggestions = get_posts( array(
            'post_type' => 'download',
            'post_status' => 'publish',
            'posts_per_page' => $max_results,
            'post__not_in' => $excluded_downloads,
            'orderby' => 'rand',
        ) );

        // Adds new suggestions to suggestions array with structure array( download_id => purchases )
        foreach($random_suggestions as $random_suggestion) {
            $suggestions[$random_suggestion->ID] = 1;
        }
    }

    return $suggestions;
}

And why I write this here? Because I do not know if this could be a new feature for the extension or a new snippet for this library and, of course, I want you suggestions to improve the code :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.