Skip to content

Instantly share code, notes, and snippets.

View robin-scott's full-sized avatar
🏠
Working from home

Rob Scott robin-scott

🏠
Working from home
View GitHub Profile
@robin-scott
robin-scott / functions.php
Last active January 30, 2022 12:14
Remove out of stock products from WooCommerce Related products
// remove OOS products from related products in WooCommerce, because they are OOS! by Robin Scott of silicondales.com - see more at https://silicondales.com/tutorials/woocommerce/remove-out-of-stock-products-from-woocommerce-related-products/
add_filter( 'woocommerce_related_products', 'exclude_oos_related_products', 10, 3 );
function exclude_oos_related_products( $related_posts, $product_id, $args ){
$out_of_stock_product_ids = (array) wc_get_products( array(
'status' => 'publish',
'limit' => -1,
'stock_status' => 'outofstock',
'return' => 'ids',
) );
@robin-scott
robin-scott / google-drive-large-wget.txt
Created January 7, 2020 13:36
Wget command for large files collection from Google Drive
// Use the below to wget in large files (over 100MB) from Google Drive. Added by Robin Scott of SiliconDales.com. See full instructions at https://silicondales.com/tutorials/g-suite/how-to-wget-files-from-google-drive/
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILE_ID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILE_ID" -O FILE_NAME && rm -rf /tmp/cookies.txt
@robin-scott
robin-scott / wgetcomman.txt
Last active January 7, 2020 13:32
Google Drive small file wget command
// Wget command to collect small files from Google Drive added by Robin Scott of silicondales.com
wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILE_ID' -O FILE_NAME
@robin-scott
robin-scott / gist:cb297a299ebe8eb8b405e32230e3c013
Last active October 28, 2019 17:24
Only use product tags in WooCommerce related products
// Remove categories and only use tags in WooCommerce related products - By Robin Scott of Silicon Dales see https://silicondales.com/tutorials/woocommerce/remove-categories-only-use-tags-related-products/
add_filter( 'woocommerce_product_related_posts_relate_by_category', '__return_false' );
@robin-scott
robin-scott / .htaccess
Created November 27, 2018 10:14
Codeigniter .htaccess for mod_rewrite - see https://silicondales.com/tutorials/codeigniter-htaccess/ for details
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
## EXPIRES CACHING - by Robin Scott of Silicon Dales, here https://silicondales.com/tutorials/seo/leverage-browser-caching-images-css-js/##
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
Order Deny,Allow
Deny from 222.222.222.222
@robin-scott
robin-scott / functions.php
Last active November 21, 2018 14:05
WooCommerce - Add extra weight to all cart items in a specific shipping class - Find out more here -> https://silicondales.com/tutorials/woocommerce/add-additional-shipping-weight-to-cart-items-in-a-shipping-class/
// By Robin Scott of Silicon Dales
// Add 6oz extra weight to all cart items in specific shipping class
// More information here: https://silicondales.com/tutorials/woocommerce/add-additional-shipping-weight-to-cart-items-in-a-shipping-class/
add_action( 'woocommerce_before_calculate_totals', 'rscott_add_custom_weight', 10, 1);
function rscott_add_custom_weight( $cart_object ) {
if ( (is_admin() && ! defined( 'DOING_AJAX' ) ) || $cart_object->is_empty() )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
$additionalweight = 6;
@robin-scott
robin-scott / htaccess
Created October 19, 2018 08:37
Deny access to wp-admin BUT allow ajax to be used in WordPress
// Add this to an .htaccess file at the top of the wp-admin directory to lock down this section of your site to only trusted IP addresses - BUT still allow ajax access
// By Robin Scott of Silicon Dales - details here: https://silicondales.com/tutorials/wordpress/lock-out-all-traffic-except-your-ip-from-login-admin/
<Files admin-ajax.php>
Order allow,deny
Allow from all
Satisfy any
</Files>
Order Deny,Allow
Deny from all