Nick Shaw

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 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;
		$rounded = round($number,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 {
		   $numbersale = ($x) / 3;	
		   $roundedsale = round($numbersale,2);	
		   $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 {
		    $numbersale = ($x) / 3;	
		    $roundedsale = round($numbersale,2);	
			$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'); 
Exit mobile version