I am currently using a shortcodes on the My Account page (WooCommerce + Wordpress) to check if a user owns that course before displaying the image and link to access the content. If I use just 1 shortcode it works beautifully. But as soon as I add a second shortcode with a different product idea it just outputs a white page.
//Displays course module image
//[checkpurchase course="" url="" img=""]
function checkpurchase_shortcode( $atts, $content = null ) {
//set default attributes and values
$values = shortcode_atts( array(
'course' => '0',
'url' => '#',
'img' => '#',
), $atts );
$content = "";
$courseid = esc_attr($values['course']);
//check if they purchased the course through WooCommerce
function check_coursepurchase($courseid) {
global $woocommerce;
$user_id = get_current_user_id();
$current_user= wp_get_current_user();
$customer_email = $current_user->email;
//if they own the product return true
if ( wc_customer_bought_product( $customer_email, $user_id, $courseid)) {
return true;
}
return false;
}
//if they own the product them display access
if( check_coursepurchase($courseid) ){
//make icon on the my account page for the course
return '<a href="'. esc_attr($values['url']) .'" target="_blank"><img src="'. esc_attr($values['img']) .'" border="0" /></a>';
}
}
add_shortcode( 'checkpurchase', 'checkpurchase_shortcode' );