Skip to content

Instantly share code, notes, and snippets.

🐞
Debugging

Jon Fuller Garconis

🐞
Debugging
Block or report user

Report or block Garconis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Garconis
Garconis / .htaccess
Created Aug 24, 2019
Cloudways | .htaccess rewrite URL to HTTPS with WWW
View .htaccess
# Cloudways force HTTPS with WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
View force-woocommerce-orders-to-automatically-complete.php
<?php
/**
* Auto Complete all WooCommerce orders.
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
@Garconis
Garconis / home-woocommerce-pages-anonymous-redirect.php
Created Aug 8, 2019
WooCommerce | Hide WooCommerce products and pages for logged-out users and redirect to homepage
View home-woocommerce-pages-anonymous-redirect.php
<?php
// redirecting woocommerce pages to homepage for logged out users
add_action( 'template_redirect', 'fs_wc_redirect' );
function fs_wc_redirect() {
if ( ! is_user_logged_in() && (is_woocommerce() || is_cart() || is_checkout()) ) {
wp_redirect( home_url() );
exit;
}
}
@Garconis
Garconis / pressable-batcache-append-to-wp-config.php
Created Aug 6, 2019
Pressable | Add custom batcache settings to end of wp-config.php file
View pressable-batcache-append-to-wp-config.php
<?php
$n = '
/** Custom Batcache settings for the end of wp-config.php **/
global $batcache;
if ($batcache && WP_CACHE) {
$batcache->max_age = 86400; // Seconds the cached render of a page will be stored
$batcache->seconds = 3600; // The amount of time at least 2 people are required to visit your page for a cached render to be stored.
}
';
@Garconis
Garconis / functions.php
Created Aug 5, 2019
How to display the Shipping Class of each item in the WooCommerce shopping cart
View functions.php
<?php
/**
* Add the shipping class to the bottom of each item in the cart
*/
add_filter( 'woocommerce_cart_item_name', 'shipping_class_in_item_name', 20, 3);
function shipping_class_in_item_name( $item_name, $cart_item, $cart_item_key ) {
// If the page is NOT the Shopping Cart or the Checkout, then return the product title (otherwise continue...)
if( ! ( is_cart() || is_checkout() ) ) {
return $item_name;
@Garconis
Garconis / woocommerce-small-image-thumbnail-cropping.php
Created Aug 2, 2019
WooCommerce | Thumbnail upscale & correct crop in WordPress
View woocommerce-small-image-thumbnail-cropping.php
<?php
/* Upscale images that are otherwise too small for thumbnail cropping */
function gc_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ){
if ( !$crop ) return null; // let the WordPress default function handle this
$aspect_ratio = $orig_w / $orig_h;
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = round($new_w / $size_ratio);
@Garconis
Garconis / woocommerce-shipping-class-in-shopping-cart.php
Created Jul 31, 2019
WooCommerce | Display the shipping class of items in the cart, and change shipping methods (and verbiage) based on the shipping classes in the cart
View woocommerce-shipping-class-in-shopping-cart.php
<?php
/**
* Hide a Flat Rate option (instance #7) when the "Call for Quote" shipping class is in the cart
* from: https://www.bolderelements.net/support/knowledgebase/hide-shipping-method-when-cart-contains-shipping-class/
*/
function fs_hide_shipping_when_class_is_in_cart( $rates, $package ) {
// shipping class IDs (slugs) that need the method removed
$shipping_classes = array('call-for-quote');
$if_exists = false;
@Garconis
Garconis / shortcode-loop-of-cpt-with-acf-fields.php
Created Jul 16, 2019
WordPress | Shortcode Loop of CPT with ACF Fields (Bing Devils score cards) [work-in-progress]
View shortcode-loop-of-cpt-with-acf-fields.php
<?php
// create shortcode to list all Games in Page
add_shortcode( 'fs-game-schedule-page-loop', 'fs_sc_game_schedule_page_loop' );
function fs_sc_game_schedule_page_loop( $atts ) {
ob_start();
// define attributes and their defaults
extract( shortcode_atts( array (
'post_type' => 'fs_schedule',
@Garconis
Garconis / cpt-remove-slug-hack.php
Last active Jul 3, 2019
WordPress | Hack to get CPT to have no post-type slug
View cpt-remove-slug-hack.php
<?php
/**
* NOTE, this causes PAGES AND POSTS TO NOT WORK!
*/
/**
* NOTE, this also requires your post type (e.g., via CPT UI) to have a Rewrite to True,
* and a Custom Rewrite Slug of / (forward slash) ... which probably isn't best practice.
* Sources:
@Garconis
Garconis / impreza-theme-options-per-cpt.php
Created Jun 12, 2019
Impreza | Help update theme meta data to certain post types (only run once)
View impreza-theme-options-per-cpt.php
<?php
$local_args = array(
'posts_per_page' => -1,
'post_type' => 'fs_local',
);
$local_posts_array = get_posts( $local_args );
foreach ( $local_posts_array as $post ) {
update_post_meta( $post->ID, 'us_header_id', '__defaults__' );
update_post_meta( $post->ID, 'us_titlebar_id', '__defaults__' );
You can’t perform that action at this time.