Skip to content

Instantly share code, notes, and snippets.

View weestack's full-sized avatar

Alexander Høgh weestack

View GitHub Profile
# Plugin main file
<?php
/*
Plugin Name: Emails Helius
Description: Changes the default user registration email and notify admin.
Version: 1.0
Author: Helius
Author URI: https://helius.dk
*/
/**
* Automatically add product to cart on visit
*/
add_action( 'template_redirect', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
$product_id = 2861; //replace with your own product id
$found = false;
//check if product already in cart
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
/* Register user at checkout */
function wc_register_guests( $order_id ) {
// get all the order data
$order = new WC_Order($order_id);
//get the user email from the order
$order_email = $order->billing_email;
// check if there are any users with the billing email as user or email
$email = email_exists( $order_email );
function set_default_featured_image($post_id, $post, $update){
if ( ! $update && ! ((bool) get_post_thumbnail_id($post_id))){
$img_id = 2675;
//$post_id = 2784;
set_post_thumbnail( $post_id, $img_id );
add_post_meta($post_id, '_thumbnail_id', $img_id);
}
}
/* Get total earnings with currency */
function get_total_earnings($atts = []) {
/*
* Posible parameters for atts start_date and end_date:
* today
* yesterday
* this_week
* last_week
* this_month
* last_month
function add_donation_names_to_give_forms(){
global $post;
$content = "";
if (get_post_type( $post->ID) == "give_forms") {
ob_start();
?> <h2>Andre donation</h2> <?php
echo do_shortcode('[give_donor_wall form_id="'.$post->ID.'"]');
$content = ob_get_clean();
}
echo $content;
/* Set default close message */
function default_give_form_closed_message($post_id, $post, $update){
if (! $update ) {
$meta_key = '_give_form_goal_achieved_message';
$meta_value = "Mange tak, vi har nået målet for indsamlingen!";
$current_close_message = get_post_meta( $post_id, '_give_form_goal_achieved_message', true );
if (empty($current_close_message))
update_post_meta($post_id, $meta_key, $meta_value, $prev_value=$current_close_message);
}
# Big Theta (n^2)
def insertion_sort(A: list):
# Start loop from 1, as 0 wont be compared to it self
for j in range(1, len(A)):
#block 1
key = A[j]
# Block 2
i = j - 1
while i > -1 and A[i] > key:
# Prints out the time it takes for a function to run
def time_runtime(function):
@wraps(function)
def wrapper(*args, **kwargs):
start = time.time()
result = function(*args, **kwargs)
end = time.time()
print("Time to run in seconds: {}".format(end-start))
return result
return wrapper
def counting_sort(A, length):
# First fint the maximum value
k = max(A)
Aux = list()
for i in range(0, k+1):
Aux.insert(i, 0)
for i in range(0, length):
Aux[A[i]] += 1