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 / acf-csv-import-no-duplicates.php
Created May 4, 2021 00:43
Import a CSV into a repeater field with ACF, removing all duplicates and leaving the last entry.
<?php
/**
* Optionally import Press articles from CSV ACF
*
* @author Travis Aaron Wagner <[email protected]>
* @return void
*/
function taxa_import_press_articles_csv() {
$csv = get_field('articles_csv');
if (!$csv) return;
@trvswgnr
trvswgnr / automatessl.md
Last active February 12, 2021 00:27
Automate Certificate Update on A Small Orange with Let’s Encrypt

Automate Certificate Update on A Small Orange with Let’s Encrypt

  1. Generate SSL cert and key if not already done: /home/yourusername/.acme.sh/acme.sh --issue -d yoursite.com -d www.yoursite.com -d mail.yoursite.com -w /home/yourusername/yoursitefolder. Note the .crt file and copy the path/filename for future use.

  2. Manually add SSL via A Small Orange cPanel, just this first time.

  3. Find corresponding .crt file in /home/yourusername/ssl/certs/ and copy path/filename. Do the same with .key file.

Add following to a cron job:

@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();
@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 / 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 / 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 / link-inputs.js
Created October 16, 2020 03:32
JS - Link inputs, selects, radios, and checkboxes.
@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 / 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 / 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(