Skip to content

Instantly share code, notes, and snippets.

@ScottDeLuzio
ScottDeLuzio / functions.php
Last active December 29, 2017 15:13
Move Conditional Checkout Fields With WooCommerce Hooks
<?php
/*
* This has not been tested, but should work in theory. Use with care.
*/
/*
* Remove the default WooCommerce Action
* Valid actions include:
* woocommerce_before_checkout_billing_form
* woocommerce_after_checkout_billing_form
@ScottDeLuzio
ScottDeLuzio / functions.php
Last active May 31, 2017 16:51
Add text before input
<?php
function show_content_before_fields(){
$contents = '<h1>Teilnehmer-Daten</h1>';
$contents .= 'Conditional fields here:<br>';
echo $contents;
}
add_action( 'cwcfp_before_checkout_fields', 'show_content_before_fields' );
@ScottDeLuzio
ScottDeLuzio / functions.php
Last active June 6, 2017 21:25
Add multiple volume discounts to EDD
<?php
/*
* Our discounts are going to be applied to two products. In this case product IDs 54 & 55. Add/modify the $product_ids array as applicable.
* Both products will get the same tiered discounts but we don't want someone to buy 10 of product 54 and 1 of product 55 and get the discount for product 55.
* So, we need to create separate discounts only if the criteria is met for each product.
* The tiered discount will look like this:
* 10-24 of any single product = 25% discount
* 25-99 of any single product = 33% discount
* 100-249 of any single product = 40% discount
* 250-499 of any single product = 45% discount
@ScottDeLuzio
ScottDeLuzio / functions.php
Last active December 29, 2017 15:13
Add content before your conditional checkout fields for WooCommerce
<?php
function show_before_field_group( $content, $repeat, $field_number ){
return 'This is some <strong>test</strong> info that will show up before each group of fields';
if( $repeat == 1 && $field_number == 2 ){
return 'This is some <strong>test</strong> info will show up only before the first instance of the field with ID 2';
}
}
add_filter( 'cwcfp_before_conditional_field_grouping', 'show_before_field_group', 10, 3 );
function show_before_each_field_id_one( $content, $repeat, $field_number ){
@ScottDeLuzio
ScottDeLuzio / functions.php
Created September 6, 2017 20:16
wpcrm_system_add_calendar_entry
function wpcrm_system_new_calendar_entry( $calendar, $month, $list_day, $year ){
// Display an entry on the calender on December 25th every year.
if ( $month == 12 && $list_day == 25 ){
$calendar .= '<li>Christmas</li>';
}
// Display an entry on the calendar on September 5th 2017
if ( $month == 9 && $list_day == 5 && $year == 2017 ){
$calendar .= '<li>This is a date specific entry</li>';
}
// Display an entry on the calendar on the 15th of every month
@ScottDeLuzio
ScottDeLuzio / functions.php
Created October 13, 2017 23:16
Create a task in WP-CRM System programatically
<?php
/*
Plugin Name: WP-CRM System Create Task
Plugin URI: https://www.wp-crm.com
Description: Create a task in WP-CRM System.
Version: 1.0
Author: Scott DeLuzio
Author URI: https://www.wp-crm.com
*/
function wpcrm_system_programmatically_create_task() {
@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;
}
@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 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 );
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;
}