Nick Shaw

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