Skip to content

Instantly share code, notes, and snippets.

View Basilakis's full-sized avatar
🏠
Working from home

Basilis Kanonidis Basilakis

🏠
Working from home
View GitHub Profile
@Basilakis
Basilakis / redirect-after-publish-v1.php
Created January 10, 2017 12:42
WordPress: Redirect to post/page after publishing
<?php
// Redirect to the post/page itself after publishing or updating a post in
// WordPress. This code is from the WordPress forum [1], modified so it doesn't
// redirect when saving a draft.
// [1]: http://wordpress.org/support/topic/redirect-to-new-post-after-publish
add_filter('redirect_post_location', function($location)
@Basilakis
Basilakis / edd-shortcodes.php
Created November 13, 2017 13:11
Easy Digital Download Shortcoddes for Open Metrics
// Avg downloads per customer
function sc_edd_avg_downloads_per_customer( $atts ) {
$amount = 0;
$query = new WP_Query( array( 'post_type' => 'download' ) );
foreach( $query->posts as $post ) {
$amount = $amount + edd_get_download_sales_stats( $post->ID );
}
$amount = $amount / edd_count_total_customers();
return number_format( $amount, 2 );
}
@Basilakis
Basilakis / testing-data.csv
Created July 18, 2022 06:25
Testing Data for WooCommerce Stores
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 1.
ID,Type,SKU,Name,Published,"Is featured?","Visibility in catalog","Short description",Description,"Date sale price starts","Date sale price ends","Tax status","Tax class","In stock?",Stock,"Backorders allowed?","Sold individually?","Weight (lbs)","Length (in)","Width (in)","Height (in)","Allow customer reviews?","Purchase note","Sale price","Regular price",Categories,Tags,"Shipping class",Images,"Download limit","Download expiry days",Parent,"Grouped products",Upsells,Cross-sells,"External URL","Button text",Position,"Meta: lw_wc_thank_you_redirect","Meta: ocean_sidebar","Meta: ocean_second_sidebar","Meta: ocean_disable_margins","Meta: ocean_display_top_bar","Meta: ocean_display_header","Meta: ocean_center_header_left_menu","Meta: ocean_custom_header_template","Meta: ocean_header_custom_menu","Meta: ocean_disable_title","Meta: ocean_disable_heading","Meta: ocean_disable_breadcrumbs","Meta: ocean_display_footer_widgets","Meta: ocean_display_footer_bottom","Meta: ocean_link_format_target","Meta: ocean_quote_for
@Basilakis
Basilakis / api.php
Last active September 9, 2021 12:40
Multiple IPN for PayPal, Stripe etc
<?php
ini_set( 'max_execution_time', 0 ); /* Do not abort with timeouts */
ini_set( 'display_errors', 'Off' ); /* Do not display any errors to anyone */
$urls = array(); /* The broadcast session queue */
/* List of IPN listener points */
$ipns = array(
'edd' => 'https://creativeg.gr/?edd-listener=IPN',
'edd_payments' => 'https://creativeg.gr/?Paypal_For_Edd=&action=ipn_handler',
@Basilakis
Basilakis / functions.php
Created June 4, 2021 14:16
Easy Digital Downloads - Suppliment shortcode to validate item in the cart and print details
/**
* Suppliment shortcode to validate item in the cart and print details
*/
function cart_content_shortcode( $atts,$cart_key, $item, $ajax = false ) {
global $post;
$cart_contents = edd_get_cart_contents();
if ( ! empty( $cart_contents ) ) {
@Basilakis
Basilakis / functions.php
Created June 4, 2021 14:14
Easy Digital Downloads - Un check all other options on a multiselect pricing, and leave only the last selected
/**
* Un check all other options on a multiselect pricing, and leave only the last selected
*/
function sumobi_edd_deselect_other_price_options() {
if ( ! edd_has_variable_prices( get_the_ID() ) )
return;
?>
<script>
jQuery(document).ready(function ($) {
@Basilakis
Basilakis / functions.php
Created June 4, 2021 14:14
Easy Digital Downloads - Modify the purchase link for downloads that are free and have only 1 download file to allow direct download bypassing checkout.
/**
* Modify the purchase link for downloads that are free and have only 1 download file to allow direct download bypassing checkout.
*/
add_filter( 'edd_purchase_download_form', 'isa_edd_purchase_form', 20, 2 );
function isa_edd_purchase_form( $purchase_form, $args ) {
$download_id = absint( $args['download_id'] );
if ( $download_id ) {
@Basilakis
Basilakis / functions.php
Created June 4, 2021 14:09
Easy Digital Downloads - Add the customer's username to the payment's "Customer Details" section and link through to their profile
/**
* Easy Digital Downloads - Add the customer's username to the payment's "Customer Details" section and link through to their profile
*/
function sumobi_edd_customer_details_username( $payment_id ) {
$user_info = edd_get_payment_meta_user_info( $payment_id );
$customer_id = $user_info['id'];
if ( ! $customer_id ) {
return;
}
@Basilakis
Basilakis / functions.php
Created June 4, 2021 14:05
Easy Digital Downloads - Add Handling Fee
function cg_add_handling_fee()
{
$current_user = wp_get_current_user();
if ($current_user !=0) {
$userId = $current_user->ID;
$subscriber = new EDD_Recurring_Subscriber($userId, true);
$subscription = new EDD_Subscription($userId); //subscriber id
//expiration date check
$expiration_date = $subscription->get_expiration();
if (strtotime($expiration_date) > strtotime('-5 day')) {
@Basilakis
Basilakis / functions.php
Created June 4, 2021 14:04
Easy Digital Downloads - Change the button text of a free download. Default is "Free - Add to Cart
/**
* Easy Digital Downloads
* Change the button text of a free download. Default is "Free - Add to Cart"
*/
function cg_edd_free_download_text_args( $args ) {
// Enter the button text for a free download
$download_id = absint( $args['download_id'] );
if ( 4915 == $download_id ) {
$args['text'] = 'Start Here';
} else {