Skip to content

Instantly share code, notes, and snippets.

View jtcote's full-sized avatar

Jayson T. Cote jtcote

View GitHub Profile
@jtcote
jtcote / woocommerce-my-account.php
Last active August 17, 2017 13:30 — forked from SiR-DanieL/functions.php
Adds VAT and SSN fields in WooCommerce workflow
// Add VAT and SSN fields in billing address display
add_filter( 'woocommerce_order_formatted_billing_address', 'custom_add_vat_ssn_formatted_billing_address', 10, 2 );
function custom_add_vat_ssn_formatted_billing_address( $fields, $order ) {
$fields['vat'] = $order->billing_vat;
$fields['ssn'] = $order->billing_ssn;
return $fields;
}
add_filter( 'woocommerce_my_account_my_address_formatted_address', 'custom_my_account_my_address_formatted_address', 10, 3 );
Array
(
[orders] => Array
(
[0] => Array
(
[id] => 3520
[order_number] => 3520
[created_at] => 2016-09-01T20:37:12Z
[updated_at] => 2016-09-01T20:37:12Z
@jtcote
jtcote / gum_woo_api_example.php
Created September 8, 2016 18:08
Woocommerce API Example
require_once 'lib/woocommerce-api.php';
$consumer_key = 'ck_b19dd8998398a762d0a5062e9fd1cef1c38bdcf1';
$consumer_secret = 'cs_12bb4182989d216d02a773586d680d481caef086';
$store_url = 'http://shop.lifespa.com/';
$options = array(
'debug' => true,
'return_as_array' => true,
'validate_url' => false,
'timeout' => 30,
@jtcote
jtcote / plugin.php
Last active April 20, 2016 20:06
WooCommerce Simple Wholesale Price
//** Wholesale pricing based on 'wholesaler' role
// checks if the current user is capable to have the wholesale pricing
function gum_woo_wholesale_pricing_applies(){
return (bool) ( current_user_can('wholesaler') && ( !is_admin() || is_ajax() ) );
}
// wholesale price when available for both Simple & Variable product type
function gum_woo_wholesale_price_get( $product ) {
if( $product->is_type( array('simple', 'variable') ) && get_post_meta( $product->id, '_wholesale_price', true ) > 0 ){
return get_post_meta( $product->id, '_wholesale_price', true );
@jtcote
jtcote / functions.php
Created April 5, 2016 16:32
Restore WP get_shortlink function in editor
//* Restore get shortlinks in editor
add_filter( 'get_shortlink', 'gumtheme_restore_wp_getshortlink' );
function gumtheme_restore_wp_getshortlink( $shortlink ) {
return $shortlink;
}
@jtcote
jtcote / functions.php
Created March 30, 2016 19:58
Set WP Admin > Settings > Reading robots access //* Discourage search engines from indexing this site
//* Discourage search engines from indexing this site
add_action('init', 'gumtheme_set_robots_access');
function gumtheme_set_robots_access(){
if(WP_ENV == 'staging' && get_option('blog_public') == '1')
update_option('blog_public', '0');
if(WP_ENV == 'production' && get_option('blog_public') == '0')
update_option('blog_public', '1');
}
@jtcote
jtcote / woo_remove_caps.php
Created November 13, 2015 21:55
Remove all Woocommerce custom capabilities from DB after deactivating Woo
//Delete old custom capabilities
add_action( 'admin_init', 'gum_delete_woo_caps' );
function gum_delete_woo_caps(){
$delete_caps = array(
'assign_product_terms',
'assign_shop_order_terms',
'assign_shop_webhook_terms',
'delete_others_products',
'delete_others_shop_coupons',
'delete_others_shop_orders',
@jtcote
jtcote / maintenance_redirect.php
Last active August 29, 2015 14:16
WP maintenance page redirect function
/***** MAINTENANCE *****/
//* Redirect for temp landing page
add_action( 'template_redirect', 'gum_redirect_maintenance_page' );
function gum_redirect_maintenance_page() {
$redirect = FALSE;
$page = home_url( '/maintenance/' ); //slug for wp page
if ( $redirect && !is_user_logged_in() && trim( $_SERVER['REQUEST_URI'], '/' ) != 'maintenance' && $_SERVER['REQUEST_URI'] != '/wp-admin/' ) :
wp_redirect( $page );
exit;
@jtcote
jtcote / gumwp_plugin_tribe_events_wootix_show_cost.php
Last active February 14, 2016 22:06
Tribe Events Plugin - wootickets add-on, show ticket cost and availability
add_filter( 'tribe_get_cost', 'gum_wootickets_tribe_get_cost', 10, 3 );
function gum_wootickets_tribe_get_cost( $cost, $postId, $withCurrencySymbol ) {
if ( empty($cost) && class_exists('TribeWooTickets') ) {
// see if the event has tickets associated with it
$wootickets = TribeWooTickets::get_instance();
$ticket_ids = $wootickets->get_Tickets_ids( $postId );
if ( empty($ticket_ids) ) {
return '';
@jtcote
jtcote / gumwp_plugins_tribe_events_condtional.php
Last active August 29, 2015 13:58
WP plugin - tribe events conditional statements
<?php
/**
* Plugin Functions
*
* @category WP Plugins
* @author Jayson T. Cote
* @link https://tri.be/shop/wordpress-events-calendar/
*/
if (tribe_is_event() || tribe_is_event_category() || tribe_is_in_main_loop() || tribe_is_view() || 'tribe_events' == get_post_type() || is_singular( 'tribe_events' )) {