Skip to content

Instantly share code, notes, and snippets.

View lukecav's full-sized avatar
🙏
If we're kind and polite, the world will be right.

Luke Cavanagh lukecav

🙏
If we're kind and polite, the world will be right.
View GitHub Profile
@lukecav
lukecav / Command
Created May 15, 2023 20:32
Get the values of the iThemes Security Pro plugin settings from WP-CLI command
wp option get itsec-storage --format=json
@lukecav
lukecav / functions.php
Created May 10, 2023 21:29
Change product tag on stock change in WooCommerce
function action_woocommerce_low_stock( $wc_get_product ) {
// Product set tag id(s), multiple IDs can be added, separated by a comma
$wc_get_product->set_tag_ids( array( 'YOUR TAG ID' ) );
// OPTIONAL: Set category ids
//$wc_get_product->set_category_ids( array( 39, 2 ) );
// Save
$wc_get_product->save();
}
@lukecav
lukecav / functions.php
Created May 10, 2023 21:26
Fix the product tab is locked issue in WooCommerce 7.7.0
function reset_product_template( $post_type_args ) {
if ( array_key_exists( 'template', $post_type_args ) ) {
unset( $post_type_args['template'] );
}
return $post_type_args;
}
add_filter( 'woocommerce_register_post_type_product', 'reset_product_template' );
@lukecav
lukecav / .htaccess
Created May 9, 2023 19:28
mod_pagespeed .htaccess configuration
<IfModule pagespeed_module>
ModPagespeed on
ModPagespeedEnableFilters recompress_jpeg,recompress_png
ModPagespeedEnableFilters recompress_webp
ModPagespeedEnableFilters convert_gif_to_png,convert_jpeg_to_progressive
ModPagespeedEnableFilters convert_jpeg_to_webp,convert_png_to_jpeg
ModPagespeedEnableFilters jpeg_subsampling
ModPagespeedEnableFilters strip_image_color_profile,strip_image_meta_data
</IfModule>
@lukecav
lukecav / Commands
Last active May 8, 2023 20:29
Useful commands to get a list of all admin users, reset the password for all admin users, shuffle the salts and them update plugins and themes using WP-CLI commands
wp user list --role=administrator --format=csv
wp user reset-password $(wp user list --fields=ID --role=administrator)
wp user reset-password $(wp user list --fields=ID --role=administrator) -skip-email
wp config shuffle-salts
wp plugin update --all
wp theme update --all
@lukecav
lukecav / functions.php
Created May 8, 2023 18:13
Change nofollow add to cart links to dofollow in WooCommerce
add_filter( 'woocommerce_loop_add_to_cart_link', 'add_to_cart_dofollow', 10, 2 );
function add_to_cart_dofollow($html, $product){
$html = sprintf( '<a rel="dofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $quantity ) ? $quantity : 1 ),
esc_attr( $product->get_id() ),
esc_attr( $product->get_sku() ),
esc_attr( isset( $class ) ? $class : 'button' ),
esc_html( $product->add_to_cart_text() )
);
@lukecav
lukecav / functions.php
Created May 4, 2023 20:39
Remove product images in the order email in WooCommerce
add_filter( 'woocommerce_email_order_items_args', 'remove_product_image_from_order_email' );
function remove_product_image_from_order_email( $args ) {
$args['show_image'] = false;
return $args;
}
@lukecav
lukecav / functions.php
Created May 4, 2023 20:00
Add currency suffix on cart and checkout pages in WooCommerce
add_filter( 'woocommerce_price_format', 'add_currency_suffix', 10, 2 );
function add_currency_suffix( $price, $currency_symbol ) {
// Only add the suffix on cart and checkout pages
if ( is_cart() || is_checkout() ) {
// Get the current currency code
$currency = get_woocommerce_currency();
@lukecav
lukecav / functions.php
Created May 4, 2023 18:13
Disable automatic creation of YARPP thumbnail sizes
add_filter( 'yarpp_add_image_size', '__return_false' );
@lukecav
lukecav / functions.php
Created May 1, 2023 16:39
Delete the Jetpack heartbeat cron event using a WP-CLI command
wp cron event delete jetpack_v2_heartbeat