Skip to content

Instantly share code, notes, and snippets.

View jondcampbell's full-sized avatar

Jon Campbell jondcampbell

View GitHub Profile
@jondcampbell
jondcampbell / gist:6fce0904461dd21d118e
Last active August 29, 2015 14:05 — forked from mikejolley/gist:1604009
Add a text field to woocommerce checkout, save the field data to user meta and order meta. Does not make the user meta show up in profile editor.
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="custom_checkout_fields"><h3>'.__('Member Listing Profile').'</h3>';
/**
@jondcampbell
jondcampbell / gist:7927e2f308b614a8083d
Created August 12, 2014 18:14 — forked from bryceadams/gist:0fe1144b34951d7bb654
Change zip label to postcal code for Canadian woocommerce customers
/*
* Change zip to postal code for canada
*/
add_filter( 'woocommerce_get_country_locale', 'fs_custom_checkout_locale' );
function fs_custom_checkout_locale( $locale ) {
$locale['CA']['postcode']['label'] = __( 'Postal Code', 'woocommerce' );
$locale['CA']['postcode']['placeholder'] = __( 'Postal Code', 'woocommerce' );
return $locale;
@jondcampbell
jondcampbell / example-query.php
Last active August 29, 2015 14:05 — forked from joshfeck/example-query.php
Query event espresso 4 events and order by the events start date. Using this instead of a wp query of espresso_events post type.
<ul class="events">
<?php
$events_args = array(
'title' => NULL,
'limit' => 100,
'css_class' => NULL,
'show_expired' => FALSE,
'month' => NULL,
'category_slug' => NULL,
'order_by' => 'start_date',
@jondcampbell
jondcampbell / pagetemplate.php
Created December 12, 2014 23:02
grab user data from drupal and import it into wordpress
<?php
// Drupal User Migration Class
class UserMigrate{
// Things that can be overridden by GET variables
public $users_start = 0;
public $users_limit = 5;
public $mode = 'preview';
public $confirm_cleanup = false;
@jondcampbell
jondcampbell / functions.php
Created January 14, 2015 19:53
add active classes to specific items in the wordpress menu
function my_custom_nav_class( $classes, $item ) {
// The $item->object_id is the actual post id that the menu $item is referencing.
// You could also compare the $item->title but it could change and then the class wouldn't be applied anymore
if ( 11 == $item->object_id ) :
// Blog
if ( is_singular( 'post' ) ) :
@jondcampbell
jondcampbell / functions.php
Created April 29, 2015 22:19
disable the billing fields at woocommerce checkout. sadly it doesnt add to your custom attributes, it just replaces them with disabled.
function custom_disable_woocommerce_billing_checkout_fields( $fields ) {
foreach ($fields['billing'] as $key => $billing_field){
$fields['billing'][$key]['custom_attributes'] = array('disabled' => 'disabled') ;
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'custom_disable_woocommerce_billing_checkout_fields' );
@jondcampbell
jondcampbell / functions.php
Created May 26, 2015 23:03
Find all woocommerce orders that have a particular product_id in it. Returns an array of order ids.
global $wpdb;
$sql = "SELECT order_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '_product_id' AND meta_value = $product_id ) AND order_item_type = 'line_item'";
$order_ids = $wpdb->get_col( $sql );
@jondcampbell
jondcampbell / template.php
Created May 29, 2015 18:57
get the label of ACF select field instead of value
echo get_field_object( 'select_field' )['choices'][ get_field( 'select_field' ) ];
@jondcampbell
jondcampbell / controller.php
Created October 9, 2015 23:08
query a prices table, finding me the companies with the most products. uses laravel and db query builder. grouping and ordering
$companies = DB::table('prices')
->select(DB::raw('company_id, COUNT(*) as total_products'))
->groupBy('company_id')
->orderBy('total_products', 'desc')
->get();
@jondcampbell
jondcampbell / cmb2setup.php
Created January 4, 2016 23:01
CMB2 File List: Don't show media from other posts. The key is the query_args that tell the media uploader to only show the resources uploaded to post 99999999999 (which I hope never exists).
$this->cmb_form->add_field( array(
'name' => 'Resource File List',
'desc' => '',
'id' => $this->cmb_prefix . 'resource_files',
'type' => 'file_list',
// 'preview_size' => array( 100, 100 ), // Default: array( 50, 50 )
'attributes' => array(
'required' => true, // Will be required only if visible.
'data-conditional-id' => $this->cmb_prefix . 'resource_type',
'data-conditional-value' => 'files',