Skip to content

Instantly share code, notes, and snippets.

@ScottDeLuzio
ScottDeLuzio / stripe.php
Last active January 25, 2024 18:13
Add card to customer account in Stripe
<?php
// Function to add a new card for your customer.
function sd_process_add_customer_card(){
$redirect = false;
if ( isset( $_POST['action'] ) && $_POST['action'] == 'add_customer_card' && wp_verify_nonce( $_POST['stripe_nonce'], 'stripe-nonce' ) ){
if ( !isset( $_POST['card_number'] ) || !isset( $_POST['card_cvc'] ) || !isset( $_POST['card_exp_month'] ) || !isset( $_POST['card_exp_year'] ) ){
$redirect = add_query_arg( array(
'card' => 'not-created',
), $_POST['redirect'] );
@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 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 / mainwp.php
Created January 25, 2017 22:55
mainwp_addsite and mainwp_editsite
// for add child site
$params = array(
'url' => 'http://childsite.com', // child site url
'name' => 'my child site', // set name
'wpadmin' => 'admin-user-name',
'unique_id' => '', // set value if needed
'groupids' => array( ... ), // array of group ids
'ssl_verify' => 0, // or 1, 2
'ssl_version' => 'auto',
'http_user' => '', // set value if needed
@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 / strip-shortcode.php
Created March 15, 2016 20:58
Strip shortcodes from the content home/blog page
<?php
/*
Plugin Name: Strip Shortcodes
Description: Strip shortcodes from home/blog posts page
*/
function strip_shortcode_from_excerpt( $content ) {
if ( is_home() ) {
$content = strip_shortcodes( $content );
}
return $content;
@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'