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 / Commands
Created June 27, 2023 19:27
WPVulnerability WP-CLI support
wp wpvulnerability core
wp wpvulnerability plugins
wp wpvulnerability themes
@lukecav
lukecav / style.css
Last active April 23, 2024 13:24
Hide Save payment information to my account for future purchases checkbox in Checkout Page in WooCommerce Stripe Payment Gateway
.form-row.woocommerce-SavedPaymentMethods-saveNew.woocommerce-validated {
display: none;
}
@lukecav
lukecav / functions.php
Created June 19, 2023 20:28
Executive the cart-fragments script only on specific pages in WooCommerce
add_filter( 'woocommerce_get_script_data', function( $script_data, $handle ) {
if ( 'wc-cart-fragments' === $handle ) {
if ( is_woocommerce() || is_cart() || is_checkout() ) {
return $script_data;
}
@lukecav
lukecav / Links
Last active June 19, 2023 20:29
cPanel v112 CentOS 7, CloudLinux 6 and 7, and RHEL 7 deprecation
@lukecav
lukecav / functions.php
Created May 26, 2023 20:09
Remove the sales price and use regular price when the stock is zero in WooCommerce
// Remove sale price and use regular price when stock is 0
function remove_sale_price_on_zero_stock( $price, $product ) {
// Check if the product is on sale and has stock
if ( $product->is_on_sale() && $product->get_stock_quantity() <= 0 ) {
$regular_price = $product->get_regular_price();
$price = wc_price( $regular_price ); // Use regular price instead of sale price
}
return $price;
}
add_filter( 'woocommerce_product_get_price', 'remove_sale_price_on_zero_stock', 10, 2 );
@lukecav
lukecav / functions.php
Created May 25, 2023 20:51
Add HTTP security headers in WordPress
function add_security_headers($headers) {
// Add X-XSS-Protection header
$headers['X-XSS-Protection'] = '1; mode=block';
// Add X-Content-Type-Options header
$headers['X-Content-Type-Options'] = 'nosniff';
// Add X-Frame-Options header
$headers['X-Frame-Options'] = 'SAMEORIGIN';
@lukecav
lukecav / functions.php
Created May 24, 2023 19:39
Only reduce stock inventory on completed orders in WooCommerce
add_action( 'init', 'custom_wc_maybe_reduce_stock_levels', 10 );
function custom_wc_maybe_reduce_stock_levels(){
// remove_action( 'woocommerce_order_status_completed', 'wc_maybe_reduce_stock_levels' );
remove_action( 'woocommerce_payment_complete', 'wc_maybe_reduce_stock_levels' );
remove_action( 'woocommerce_order_status_processing', 'wc_maybe_reduce_stock_levels' );
remove_action( 'woocommerce_order_status_on-hold', 'wc_maybe_reduce_stock_levels' );
add_action( 'woocommerce_payment_complete', 'wc_maybe_increase_stock_levels' );
add_action( 'woocommerce_order_status_processing', 'wc_maybe_increase_stock_levels' );
@lukecav
lukecav / Command
Created May 24, 2023 19:18
Run a site scan in iThemes Security Pro from WP-CLI command
wp itsec site-scanner scan
@lukecav
lukecav / functions.php
Created May 19, 2023 19:15
Stay logged in to wp-admin (WordPress Dashboard) for 48 hours in WordPress
function extend_auth_cookie_expiration( $expiration, $user_id, $remember ) {
// Set the desired cookie expiration time (48 hours in this example)
$cookie_expire = 2 * DAY_IN_SECONDS;
// Return the new expiration time
return $cookie_expire;
}
add_filter( 'auth_cookie_expiration', 'extend_auth_cookie_expiration', 10, 3 );