Skip to content

Instantly share code, notes, and snippets.

@ScottDeLuzio
ScottDeLuzio / functions.php
Created May 10, 2021 22:38
Switch the Admin Color Scheme for a user on various multisite subsites
/**
* Force Admin Color Scheme on admin pages for a user account based on the site we're on.
* Valid admin_color values include:
* - fresh (Default)
* - light
* - modern
* - blue
* - coffee
* - ectoplasm
* - midnight
@ScottDeLuzio
ScottDeLuzio / functions.php
Last active April 5, 2021 20:18
Filters the discount code generated in Subscriber Discounts for WooCommerce
add_filter( 'sdwoo_discount_code', 'custom_subscriber_discount_code', 10, 2 );
function custom_subscriber_discount_code( $final_code, $email_address ) {
// Start a new discount code.
$new_code = '10OFF-';
// Maximum length of the random string of characters after the new code.
$max_length = 4;
// Choose a random starting point to shorten the string to help avoid repeated strings.
$rand_start = rand( 0, 6 );
@ScottDeLuzio
ScottDeLuzio / functions.php
Created May 21, 2019 18:29
Include multiple download IDs in limit one per customer in EDD
add_action( 'edd_before_purchase_form', 'sd_set_purchase_limit_error' );
function sd_set_purchase_limit_error(){
$user_id = get_current_user_id(); // Get the current customer's ID
$downloads = edd_get_users_purchased_products( $user_id ); // Get all of the products the customer has purchased in the past
$can_checkout = true; // Allow checkout for now
$download_ids = array( 1,2,3 ); //Whatever the IDs are that you want to check for
foreach ( $download_ids as $download_id ){
$in_cart = edd_item_in_cart( $download_id ); // Check to see if our download is in the customer's cart. Change 57 to your download's ID.
if ( $in_cart == true ){ // If the item isn't in the customer's cart we don't need to go any further.
@ScottDeLuzio
ScottDeLuzio / functions.php
Last active November 20, 2018 16:31
Save empty conditional fields with order in Conditional Woo Checkout Field Pro
// Add this to your theme's functions.php file or a custom plugin.
add_action( 'woocommerce_checkout_update_order_meta', 'conditional_checkout_field_pro_update_order_meta_blank_entries_only' );
function conditional_checkout_field_pro_update_order_meta_blank_entries_only( $order_id ) {
global $wpdb, $cwcfp_db_table;
$fields = $wpdb->get_results("SELECT * FROM " . $cwcfp_db_table . " ORDER BY id;");
//Check to see if the checkout has been processed already or not
$did_process = get_post_meta( $order_id, '_cwcfp_did_process', true );
switch ( $did_process ) {
@ScottDeLuzio
ScottDeLuzio / functions.php
Created August 10, 2018 18:04
Filter datepicker options
// Copy below into your child theme's functions.php or into a custom plugin.
// Change the days of the week to French
add_filter( 'cwcfp_datepicker_day_names', 'my_custom_day_names' );
function my_custom_day_names( $days ){
$new_days = array(
'Dimanche',
'Lundi',
'Mardi',
'Mercredi',
@ScottDeLuzio
ScottDeLuzio / datepicker.js
Created August 10, 2018 17:35
Filters and defaults for datepicker in Conditional Woo Checkout Field Pro
'cwcfp_datepicker_append_text' Default: ''
'cwcfp_datepicker_auto_size' Default: false
'cwcfp_datepicker_button_image' Default: ''
'cwcfp_datepicker_button_image_only' Default: false
'cwcfp_datepicker_change_month' Default: true
'cwcfp_datepicker_change_year' Default: true
'cwcfp_datepicker_close_text' Default: 'Done'
'cwcfp_datepicker_constrain_input' Default: true
'cwcfp_datepicker_current_text' Default: 'Today'
'cwcfp_datepicker_date_format' Default: 'MM d, yy'
add_filter( 'wpcrm_system_zapier_contact_data_filter', 'get_contacts_company_url' );
function get_contacts_company_url( $data, $post_id ){
// get the organization's ID number
$org_id = get_post_meta( $post_id, '_wpcrm_contact-attach-to-organization', true );
// retrieve the organization's website URL and add to the $data array
$data['orgurl'] = get_post_meta( $org_id, '_wpcrm_organization-website', true );
// return $data
return $data;
}
@ScottDeLuzio
ScottDeLuzio / functions.php
Created November 3, 2017 17:18
Format and validate postal codes for Poland in WooCommerce
<?php
/* This will "normalize" the postcode entered by the customer, if the country seleced is Poland.
* Normalize meaning that it doesn't matter if they entered the post code as xx-xxx or xxxxx the
* function will be able to format it correctly. Once a "normalized" postcode is generated, the
* function will add a hyphen (-) in between the 2nd and 3rd numbers in the post code.
* This will always generate a xx-xxx formatted postcode.
*/
add_filter( 'woocommerce_format_postcode', 'sd_add_poland_post_code_format', 10, 2 );
function sd_add_poland_post_code_format( $postcode, $country ){
$postcode = wc_normalize_postcode( $postcode );
@ScottDeLuzio
ScottDeLuzio / functions.php
Created October 31, 2017 17:05
Redirect new user registrations from WP-CRM System client area add-on
add_filter( 'wpcrm_system_client_area_registration_redirect', 'my_url_redirect' );
function my_url_redirect( $url ){
$url = 'https://google.com';
return $url;
}
@ScottDeLuzio
ScottDeLuzio / functions.php
Created October 19, 2017 19:06
Filters the output of radio buttons in Conditional Woo Checkout Field Pro
<?php
add_filter( 'cwcfp_radio_input_filter', 'custom_radio_button_field', 10, 4 );
function custom_radio_button_field( $option_key, $option_text, $key, $value ){
$options = '<label class="radio-input block">' . $option_text . '</label><input type="radio" name="' . $key . '" id="' . $key . '" value="' . $option_key . '" ' . selected( $value, $option_key, false ) . 'class="select">' . $option_text . "\r\n";
return $options;
}