Skip to content

Instantly share code, notes, and snippets.

View tharmann's full-sized avatar

Tate Harmann tharmann

View GitHub Profile
@tharmann
tharmann / functions.php
Last active January 11, 2017 21:09
Add a checkbox to WooCommerce order form to process MailChimp API 3.0 list member subscriptions (placed after T&C checkbox if enabled on order form)
<?php
//add action to process mailchimp signup if checked
function mc_checkout_field_process() {
//only run the following if the option to subscribe has been selected
if ( $_POST['mc-subscribe'] == 'on' ) {
//retrieve email, first, and last name from form
$email = $_POST['billing_email'];
$first_name = $_POST['billing_first_name'];
$last_name = $_POST['billing_last_name'];
@tharmann
tharmann / functions.php
Last active April 27, 2016 18:31
Append count in parentheses to each menu item on menu of WooCommerce Product Categories
<?php
//add the count to our shop menu items
function nim_menu_item_count( $items, $menu, $args ) {
// Only proceed if we are looking at the correct menu and not in the admin
if ( $menu->slug != 'your-menu-slug' || is_admin() )
return $items;
//grab each menu item and it's object_id (which ends up being the category ID for the product category)
foreach ($items as $item) {
@tharmann
tharmann / functions.php
Created April 6, 2016 17:27
Add a more descriptive tooltip to the CVC field on the WooCommerce order form credit card fields
<?php
//add tooltip to cvc field
function custom_credit_card_fields_cis_cc ($cc_fields , $payment_id){
$cc_fields['card-cvc-field'] = str_replace('<p class="form-row form-row-last">','<p class="form-row form-row-last" title="3-digit security code usually found on the back of your card. American Express cards have a 4-digit code located on the front.">',$cc_fields['card-cvc-field']);
return $cc_fields;
}
add_filter( 'woocommerce_credit_card_form_fields' , 'custom_credit_card_fields_cis_cc' , 10, 2 );
@tharmann
tharmann / facebook-mass-deleter.php
Last active October 3, 2016 19:43
This is a simple snippet that I intent to complexify later. I used it to remove 1000+ posts that were created automatically (via a WordPress plugin) on a Facebook page. It takes a search string and looks for posts matching that string - then it deletes them. Keep in mind that you have to use FB's paging scheme to search through a large number of…
<?php
//make sure your page access token has the 'publish_actions' scope
$access_token = 'YOURACCESSTOKEN';
$pageid = 'YOURPAGEID';
//fb graph api only allows this to be up to 100
$limit = '100';
//retireve posts on specific page ID:
$fb_ret_url = 'https://graph.facebook.com/' . $pageid . '/posts?limit=' . $limit . '&access_token=' . $access_token;
<?php
function clear_jetpack_published() {
if(empty($_REQUEST['post'])) {
wp_die(__('Invalid post ID or action'));
}
global $wpdb;
$id = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : '';
@tharmann
tharmann / wp_xml_replacer.py
Last active May 11, 2017 15:57
A little python script for notepad++. This searches through a WordPress xml export file and converts date strings to unix timestamps. Very useful when using wp-types for custom date fields. Requires the notepad++ python plugin..
import time
import datetime
editor.beginUndoAction()
def calculate(match):
epoch = datetime.datetime(1970, 1, 1)
s = "%s/%s/%s" % (match.group(1), match.group(2), match.group(3))
t = datetime.datetime.strptime(s, "%Y/%m/%d")
diff = t-epoch
<?php
function mail_from() {
$emailaddress = 'contact@1stwebdesigner.com';
return $emailaddress;
}
function mail_from_name() {
$sendername = "1stWebDesigner.com - Dainis";
return $sendername;
}
@tharmann
tharmann / gw-gravity-forms-populate-field-value-into-subsequent-field.php
Created December 21, 2017 20:03 — forked from spivurno/gw-gravity-forms-populate-field-value-into-subsequent-field.php
Gravity Wiz // Gravity Forms // Populate Field Value from One Page to Field in Subsequent Page
/**
* Gravity Wiz // Gravity Forms // Populate Field from One Page to Field in Subsequent Page
* http://gravitywiz.com/
*/
// update "1074" to the ID of your form
add_filter( 'gform_pre_render_1074', function( $form ) {
foreach( $form['fields'] as &$field ) {
// update "2" to the field ID on the later page
@tharmann
tharmann / teedy.php
Last active January 11, 2018 20:18
A tedious and inefficient line of php written by "anonymous" hehe
<?php
$items = array(
1 => array( 'item' => explode( '|', rgar( $entry, '20' ) ), 'title' => rgar( $entry, '5' ), 'name' => rgar( $entry, '7' ), 'company' => rgar( $entry, '8' ), 'position' => rgar( $entry, '9' ), 'address_1' => rgar( $entry, '10.1' ), 'address_2' => rgar( $entry, '10.2' ), 'city' => rgar( $entry, '10.3' ), 'state' => rgar( $entry, '10.4' ), 'zip' => rgar( $entry, '10.5' ), 'country' => rgar( $entry, '10.6' ), 'phone' => rgar( $entry, '33' ), 'fax' => rgar( $entry, '11' ), 'old_pos' => rgar( $entry, '13' ), 'emp_dates' => rgar( $entry, '14' ), 'contact_rel' => rgar( $entry, '15' ), 'new_pos' => rgar( $entry, '18' ), 'reason_left' => rgar( $entry, '16' ), 'last_sal' => rgar( $entry, '17' ), 'add_notes' => rgar( $entry, '21' ), 'rush' => explode( '|', rgar( $entry, '22.1' ) ), 'international' => explode( '|', rgar( $entry, '23.1' ) ) ),
2 => array( 'item' => explode( '|', rgar( $entry, '46' ) ), 'title' => rgar( $entry, '49' ), 'name' => rgar( $entry, '51' ), 'company' => rgar( $entry, '52'
@tharmann
tharmann / functions.php
Created February 15, 2018 15:20 — forked from mantismamita/functions.php
Force SSL for media library
function have_https_for_media( $url ) {
if ( is_ssl() )
$url = str_replace( 'http://', 'https://', $url );
return $url;
}
add_filter( 'wp_get_attachment_url', 'have_https_for_media' );