Select Page

Show remaining cost on WooCommerce site to get free shipping

Add this to the functions.php file and then add the shortcode of [shippingleft] to get it to show up.

function how_much_shipping_is_left() {
   $min_amount = 100; //change this to your free shipping threshold   
   $current = WC()->cart->subtotal;  
   if ( $current < $min_amount ) {
	  $added_text = 'Get free shipping if you order ' . wc_price( $min_amount - $current ) . ' more!';
	  $notice = sprintf( '%s', $added_text );
      return $notice;
   } else {
	   $notice = "Order total is over £100 and shipping is free";
	   return $notice;
   } 
}
add_shortcode('shippingleft', 'how_much_shipping_is_left');

WooCommerce hide Klarna payment method if order total is under £35

Add this to the functions.php to hide Klarna payment method if the order total is under £35

//hide klarna if order total is under £35
add_filter( 'woocommerce_available_payment_gateways', 'rudr_turn_off_cod' );
function rudr_turn_off_cod( $available_gateways ) {	
	if( is_admin() ) {
		return $available_gateways;
	}	
	// STEP 1: Get order/cart total
	if( is_wc_endpoint_url( 'order-pay' ) ) { // Pay for order page		
		$order_id = wc_get_order_id_by_order_key( $_GET[ 'key' ] );
		$order = wc_get_order( $order_id );
		$order_total = $order->get_total();		
	} else { // Cart/Checkout page
		$order_total = WC()->cart->total;
	}	
	// STEP 2: Disable payment gateway if order/cart total is less than 35
	if ( $order_total < 35 ) {
		unset( $available_gateways[ 'klarna_payments' ] ); // unset klarna
	}
	return $available_gateways;
}

Show users how much they need to spend to qualify for Klarna on a WooCommerce site

Add this to the functions.php file and then add the shortcode of [dividebyklarna] to get it to show up.

// function that runs when shortcode is called
function wpb_nick_klarna() {  
	global $product;
	$klarnaprice = get_post_meta( get_the_ID(), '_regular_price', true);
	$klarnasaleprice = get_post_meta( get_the_ID(), '_sale_price', true);		
		$y = $klarnaprice;
		$x = $klarnasaleprice;	
		$number = ($y) / 3;
		$numbersale = ($x) / 3;	
		$rounded = round($number,2);
		$roundedsale = round($numbersale,2);	
	
if ( $product->is_type( 'simple' ) ) {	
	if($klarnaprice >=35 && $klarnaprice <=2000000 ) {		
		if(empty($klarnasaleprice)){			
		   $message = '<div class="makepaymentsblock klarnablock">Make 3 payments of '
		   .$message = '£'.$rounded  	
		   .$message = ' using <strong>Klarna</strong> with no fees and 0% interest. <a class="sg-popup-id-24192" href="">Read More</a></div>';					
		} else {
		   $message = '<div class="makepaymentsblock klarnablock">Make 3 payments of '
		   .$message = '£'.$roundedsale  	
		   .$message = ' using <strong>Klarna</strong> with no fees and 0% interest. <a class="sg-popup-id-24192" href="">Read More</a></div>';			
		}		 
	} else {
		if(empty($klarnasaleprice)){		
        	$message = '<div class="makepaymentsblock klarnablock">The minimum amount for Klarna is £35 <br/><a class="sg-popup-id-24192" href="">Read More</a></div>';
		} else {
			$message = '<div class="makepaymentsblock klarnablock">The minimum amount for Klarna is £35 <br/><a class="sg-popup-id-24192" href="">Read More</a></div>';
		}
	}
// Output needs to be return
return $message;
}
} 
// register shortcode
add_shortcode('dividebyklarna', 'wpb_nick_klarna'); 

Show users how much they need to spend to qualify for PayPal on a WooCommerce site

Add this to the functions.php file and then add the shortcode of [dividebypaypal] to get it to show up.

// function that runs when shortcode is called
function wpb_nick_paypal() {  
	global $product;
	$paypalprice = get_post_meta( get_the_ID(), '_regular_price', true);
	$paypalsaleprice = get_post_meta( get_the_ID(), '_sale_price', true);	
		$y = $paypalprice;
		$x = $paypalsaleprice;
		$number = ($y) / 4;
		$numbersale = ($x) / 4;	
		$rounded = round($number,2);
		$roundedsale = round($numbersale,2);	

if ( $product->is_type( 'simple' ) ) {	
	if($paypalprice >=99 && $paypalprice <=2000000 ) {
		if(empty($paypalsaleprice)){
			$message = '<div class="makepaymentsblock paypalblock">Make 4 payments of '
	   		.$message = '£'.$rounded  		   
	   		.$message = ' using <strong>PayPal Credit</strong> with no fees and 0% interest. <a class="sg-popup-id-24194" href="">Read More</a></div>';
		} else {
			$message = '<div class="makepaymentsblock paypalblock">Make 4 payments of '
	   		.$message = '£'.$roundedsale  		   
	   		.$message = ' using <strong>PayPal Credit</strong> with no fees and 0% interest. <a class="sg-popup-id-24194" href="">Read More</a></div>';
		}			
	} else {			
		if(empty($paypalsaleprice)){
			$message = '<div class="makepaymentsblock paypalblock">The minimum amount for PayPal Credit is £99 <br/><a class="sg-popup-id-24194" href="">Read More</a></div>';
		 } else {
			$message = '<div class="makepaymentsblock paypalblock">The minimum amount for PayPal Credit is £99 <br/><a class="sg-popup-id-24194" href="">Read More</a></div>';		
		 }		
	}
	
// Output needs to be return
return $message;
}
} 
// register shortcode
add_shortcode('dividebypaypal', 'wpb_nick_paypal'); 

Output additional image sizes on the frontend of WordPress

Use this to find all the additional image sizes your site is using

/* Output all image sizes on the frontend
---------------------------------------------------------------------------------------------------- */	 
add_action('init', 'get_all_image_sizes');

function get_all_image_sizes(){
    global $_wp_additional_image_sizes; 
    print '<pre>'; 
    print_r( $_wp_additional_image_sizes ); 
    print '</pre>';
}

Disable Divi Custom Post Type CSS file

Add this to your functions files to disable/remove the Divi CPT CSS file from being used.

/* Disable Divi CPT CSS */
function disable_cptdivi() {
	remove_action( 'wp_enqueue_scripts', 'et_divi_replace_stylesheet', 99999998 );
}
add_action('init', 'disable_cptdivi');
add_filter( 'woocommerce_product_tabs', 'bbloomer_remove_product_tabs', 9999 );

How to enable WordPress debug mode and log errors

To enable error logging, create an empty file named “php-errors.log”. Place it in a directory that is not publicly accessible (preferably outside your web root) and ensure it is writable by the web server. Then add the following code to wp-config.php:

@ini_set('log_errors', 'On');
@ini_set('error_log', '/full/path/to/php-errors.log');

By default, only fatal errors and warnings will be logged. To also log notices and other messages, enable the WP_DEBUG option by adding this code:

//Report all types of errors.
define('WP_DEBUG', true);
//Don't show errors to site visitors.
define('WP_DEBUG_DISPLAY', false);

Remove query strings from static resources in WordPress

Use this to remove query strings from static resources in WordPress

// Remove query strings from static resources
function _remove_script_version( $src ){
	$parts = explode( '?ver', $src );
	return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

Leverage Browser Caching in WordPress via .htaccess

Add this to your .htacess to Leverage Browser Caching

## https://crunchify.com/how-to-speed-up-wordpress-leveraging-browser-caching-via-htaccess/
## EXPIRES CACHING ##
<IfModule mod_expires.c>
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 text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"

ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

<FilesMatch "\\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>

<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

How to delete all images from your WordPress site

Use this SQL to remove all images/documents/etc from your media library

1 – Run these in phpmyadmin

DELETE FROM wp_postmeta
WHERE post_id IN
(
SELECT id
FROM wp_posts
WHERE post_type = 'attachment'
)
;
DELETE FROM wp_posts WHERE post_type = 'attachment'

2 – Manually delete all the year folders in the /wp-content/uploads folder.

Archives