Skip to content

Instantly share code, notes, and snippets.

View gabelloyd's full-sized avatar

Gabe Lloyd gabelloyd

View GitHub Profile
@gabelloyd
gabelloyd / woocommerce-change-default-thumbnail.php
Created May 4, 2017 18:08
Set a WooCommerce custom default thumbnail and avoid mixed-content errors with SSL
/**
* Change default thumbnail
* @since 1.0
* @author Gabe Lloyd
* ref: https://core.trac.wordpress.org/ticket/25449
*/
add_action( 'init', 'custom_fix_thumbnail' );
function custom_fix_thumbnail() {
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
@gabelloyd
gabelloyd / archive-product.php
Created April 20, 2017 16:53
Display WooCommerce featured images on archive-product.php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
get_header( 'shop' ); ?>
<?php
/**
* woocommerce_before_main_content hook.
*
@gabelloyd
gabelloyd / wp-caption-responsive.js
Created April 13, 2017 15:48
Make WP Captions Responsive to image widths.
function caption_responsive(){
//// Make captions responsive
// we want to change the width of the figcaptions within figures
$('.wp-caption').each(function(){
var caption = $(this),
figcaption = caption.find('figcaption').first(),
img = caption.find('img[class*="wp-image-"]').first();
if (img.length) {
// wait for the image to load or it might have no dimensions
@gabelloyd
gabelloyd / style-loaded-or-broken-images.js
Last active April 3, 2017 17:03
Add or remove styling classes to images depending if they load or not. Uses desandro's imagesloaded.js
/*
* Support Images loading or not
* if there are broken images, we hide the broken image icon with a "lazy" class
* add img-enhance-ui class to all images in theme.
* http://codepen.io/ire/pen/xVxgeo
* using "broken-3" styles
*
* If the images load, we will add class "appear" so they will fade in nicely.
* this is not optimized to be hooked into the scrolling behavior, just page load
* http://codepen.io/desandro/pen/bIFyl
@gabelloyd
gabelloyd / acf-check-array-value.php
Last active March 29, 2017 15:22
ACF Check if Value is set
// ACF Fields, we want to check if the values being returned are arrays
// We allow this multiple choice field to be blank in the admin, so the $value can return null, which is not an array.
// If we don't check if $value is not there, we get an error with the implode() function
$section_top_bottom_padding_array = get_sub_field_object('section_top_bottom_padding');
$value = $section_top_bottom_padding_array['value'];
if (is_array($value)) {
$section_top_bottom_padding_array_output = implode(" ", $value);
} else { // need to declare null if the array is empty
$section_top_bottom_padding_array_output = null;
@gabelloyd
gabelloyd / wc_hide_alt_shipping_if_free.php
Created February 21, 2017 19:33
WooCommerce function to hide all other shipping methods if Free Shipping qualifications are met.
//// HIDE OTHER SHIPPING METHORDS IF FREE IS AVAILABLE
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
@gabelloyd
gabelloyd / filter_woocommerce_price_input.php
Last active January 5, 2017 23:38
Filter the price input field for Name Your Price WooCommerce Extension
/*
* Replace title and type input on the price input field for Name Your Price
* Ref: https://gist.github.com/helgatheviking/e1326e2047ed621158f86c1d4747e9bc
*
* @param string $input - the <input> tag
* @param string $product_id
* @param string $prefix - needed for composites and bundles
* @return string
*/
.flexyflexflex {
display: flex;
width: 100%;
flex-direction: row;
flex-wrap: nowrap;
flex-shrink: 0;
justify-content: flex-start;
}
.flexyflexflex form {
@gabelloyd
gabelloyd / illustrator.saveall.jsx
Last active August 29, 2015 14:19
Save all open docs in Illustrator (any version)
// save all open docs in Illustrator
// originally by carlos canto
// http://forums.adobe.com/message/6161400?tstart=0#6161400
for (i=0; i<app.documents.length; i++)
{
var idoc = app.documents[i];
//alert("+"+idoc.path+"+");
if (idoc.path == "")
@gabelloyd
gabelloyd / fonselector.dropup.html
Created November 25, 2014 22:19
Fontselector Dropup
<div class="form-group">
<label class="control-label sr-only" for="fonts">Fonts</label>
<div class="btn-group dropup">
<label class="control-label" for="fonts">Choose Your Fonts</label>
<div id="fontSelect" class="fontSelect">
<div class="arrow-down"></div>
</div>
</div>