Skip to content

Instantly share code, notes, and snippets.

View webaware's full-sized avatar

Ross McKay webaware

View GitHub Profile
@webaware
webaware / add-to-cart.php
Last active October 22, 2023 05:55 — forked from mikejolley/functions.php
WooCommerce purchase page add-to-cart with quantity and AJAX, by customising the add-to-cart template in the WooCommerce loop. See blog post for details: http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
View add-to-cart.php
<?php
/**
* Loop Add to Cart -- with quantity and AJAX
* requires associated JavaScript file qty-add-to-cart.js
*
* @link http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
* @link https://gist.github.com/mikejolley/2793710/
*/
// add this file to folder "woocommerce/loop" inside theme
@webaware
webaware / gf-country-usa.php
Last active September 30, 2023 02:38
change United States to USA in Gravity Forms addresses, with support for Gravity Forms Address Enhanced
View gf-country-usa.php
<?php
/*
Plugin Name: GF Country USA
Plugin URI: https://gist.github.com/webaware/edba921af11f06bdfd5147bab806f591
Description: change United States to USA in Gravity Forms addresses
Version: 2
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
@webaware
webaware / force-ssl-url-scheme.php
Last active September 3, 2023 00:05
For WordPress, force the protocol scheme to be HTTPS when is_ssl() doesn't work, e.g. on a load-balanced server where _SERVER['HTTPS'] and _SERVER['SERVER_PORT'] don't indicate that SSL is being used. NB: may not be needed now, see SSL Insecure Content Fixer and HTTP Detection: https://ssl.webaware.net.au/https-detection/
View force-ssl-url-scheme.php
<?php
/*
Plugin Name: Force SSL URL Scheme
Plugin URI: https://gist.github.com/webaware/4688802
Description: Force the protocol scheme to be HTTPS when is_ssl() doesn't work
Version: 1.0.0
Author: WebAware
Author URI: http://webaware.com.au/
@ref: http://wordpress.org/support/topic/ssl-insecure-needs-35-compatibility
@webaware
webaware / plugin-download.php
Created June 18, 2023 04:38
Add download links to WordPress plugins with updates available
View plugin-download.php
<?php
/*
Plugin Name: Plugin Download
Plugin URI: https://gist.github.com/webaware/4a4f2dca44b1c10fb9a8fe85a5f90f40
Update URI: plugin-download
Description: add download links to plugins with updates available
Version: 0.0.1
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
@webaware
webaware / gist:6260468
Last active June 6, 2023 18:00
WooCommerce purchase page add-to-cart with quantity and AJAX, without customising any templates. See blog post for details: http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
View gist:6260468
<?php
/**
* start the customisation
*/
function custom_woo_before_shop_link() {
add_filter('woocommerce_loop_add_to_cart_link', 'custom_woo_loop_add_to_cart_link', 10, 2);
add_action('woocommerce_after_shop_loop', 'custom_woo_after_shop_loop');
}
add_action('woocommerce_before_shop_loop', 'custom_woo_before_shop_link');
@webaware
webaware / network-lister.php
Last active May 14, 2023 03:56
Simple dashboard widget for listing WordPress multisite sites, and accompanying shortcode for the front end.
View network-lister.php
<?php
/*
Plugin Name: Network Lister
Plugin URI: https://gist.github.com/webaware/b914967f0ce8110c775cd12ddc546283
Update URI: network-lister
Description: simple dashboard widget for listing network sites
Version: 0.0.5
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
@webaware
webaware / chequerboard.css
Last active April 17, 2023 23:23
Give something a grey / white chequerboard background, in two lines of CSS. Stolen from somewhere on Stack Overflow IIRC.
View chequerboard.css
.my-element {
background-image: conic-gradient(#ddd 25%, #fff 25%, #fff 50%, #ddd 50%, #ddd 75%, #fff 75%);
background-size: 40px 40px;
}
@webaware
webaware / gist:4048580
Created November 9, 2012 22:02
basic example of populating a form from a database using AJAX and JSON, jQuery version
View gist:4048580
<?php
// jQuery version of https://gist.github.com/3110728
/*
-- the SQL database table
create table form_ajax (
ID varchar(5) not null,
Name varchar(100),
Address varchar(100),
View gf-countries-woo.php
<?php
/*
Plugin Name: GF Countries for WooCommerce
Plugin URI: https://gist.github.com/webaware/985156c48d8fea3cc77d9a9c624aad18
Update URI: gf-countries-woo
Description: restrict Gravity Forms addresses to WooCommerce-allowed countries
Version: 2
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
@webaware
webaware / video.twig
Last active November 30, 2022 02:14
Replace the HTML for the standard WordPress video shortcode, simplifying it to just a video element without extra wrapping divs, buttons, etc. See blog post https://snippets.webaware.com.au/howto/wordpress-video-in-the-block-editor/
View video.twig
<video class="project-video" controls controlslist="nodownload" playsinline disablePictureInPicture
{%- if video.autoplay %} autoplay muted {%- endif -%}
{%- if video.preload %} preload="{{ video.preload }}" {%- endif -%}
{%- if video.loop %} loop {%- endif -%}
{%- if video.width %} width="{{ video.width }}" {%- endif -%}
{%- if video.height %} height="{{ video.height }}" {%- endif -%}
{%- if video.poster %} poster="{{ video.poster }}" {%- endif -%}
>
{%- for source in video.sources -%}