Skip to content

Instantly share code, notes, and snippets.

View trvswgnr's full-sized avatar
:octocat:
hardly workin'

Travis Wagner trvswgnr

:octocat:
hardly workin'
View GitHub Profile
@trvswgnr
trvswgnr / get_county_by_zip.php
Last active August 31, 2020 03:46
PHP - Get county name by zip code
<?php/**
* Get county name by zip code
*
* @param string|int $zip Zip code to lookup.
* @return string $countyname Formatted county name.
*/
function get_county_by_zip( $zip ) {
// google maps api.
$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $zip . '&key=AIzaSyC3TG7THSJjHbzDpYyQagJvWP-Inu6i33s';
$response = json_decode( file_get_contents( $url ), true );
@trvswgnr
trvswgnr / curl_get_contents.php
Last active August 31, 2020 15:59
PHP - Get contents of remote url using cURL
<?php
/**
* Get contents of remote url
*
* @see https://knowledgecornor.blogspot.com/2013/10/filegetcontents-vs-curl.html
* @author Travis Aaron Wagner
*
* @param string $url URL to get.
* @return string $output Remote url contents.
*/
@trvswgnr
trvswgnr / keys_containing.php
Created August 31, 2020 18:39
PHP - filter array by keys containing, not containing
<?php
/**
* Return array with only keys containing a string
*
* @param string $str String to filter keys by.
* @param array $arr Source array.
* @return array Filtered array.
*/
function keys_containing( $str, $arr ) {
return array_filter(
@trvswgnr
trvswgnr / woocommerce-product-to-js.php
Created September 21, 2020 22:06
pass product data to javascript
<?php
add_action( 'wp_head', function() {
global $product;
wp_localize_script('main-js-script-name', 'product', $product->get_data() );
} );
@trvswgnr
trvswgnr / codeship-wpengine.sh
Last active October 2, 2020 03:25
codeship build to wpengine
rm -rf .git/
git init
rm .gitignore
mv .gitignore-deploy .gitignore
cd wp-content/themes/moonfab/
npm install
npm run dev
git config --global user.name "CodeShip deployment"
git config --global user.email "[email protected]"
git remote add dev [email protected]:production/moonfabdev.git
@trvswgnr
trvswgnr / link-inputs.js
Created October 16, 2020 03:32
JS - Link inputs, selects, radios, and checkboxes.
@trvswgnr
trvswgnr / recursive_filter_keys.php
Last active October 16, 2020 18:06
PHP - Filter keys in multidimensional array
<?php
/**
* Filter keys in multidimensional array.
*
* @param mixed $arr The array to filter.
* @param mixed ...$keys Keys to remove. Accepts multiple strings or an array of strings.
* @return array $new Array without specified keys.
*/
function recursive_filter_keys( &$arr, ...$keys ) {
if ( isset( $keys[0] ) && is_array( $keys[0] ) ) {
@trvswgnr
trvswgnr / mu-plugin.php
Last active November 2, 2020 21:00
Must-use Local Plugin WooCommerce
<?php
/**
* Must-use plugin
*
* @package taw
*/
add_action(
'admin_head',
function() {
@trvswgnr
trvswgnr / wc-get-free-shipping-mininum.php
Last active November 11, 2020 21:53
Get minimum for free shipping set in WooCommerce settings
<?php
/**
* Get free shipping minimum
*
* @param string $zone_name Zone name.
* @return int $min_amount Minimum for free shipping.
*/
function get_free_shipping_minimum( $zone_name = '' ) {
if ( empty( $zone_name ) ) {
return null;
@trvswgnr
trvswgnr / display_price_in_variation_options.php
Last active November 16, 2020 23:48
Display price in variation option dropdown for products that have only one attribute.
<?php
/**
* Display price in variation options dropdown for products that have only one attribute.
*
* @author Travis Aaron Wagner <[email protected]>
* @param string $term Existing option term value.
* @return string $term Existing option term value or updated term value with price.
*/
function display_price_in_variation_options( $term ) {
$product = wc_get_product();