Sell unit content as product using the following shortcode:
[sell_content product_id="Enter the id of the product here"] Add the unit content here.... [/sell_content]
Add the following code in child theme functions.php or in customizer_class.php
if (!function_exists('vibe_sell_content')) {
function vibe_sell_content( $atts, $content = null ) {
extract(shortcode_atts(array(
'product_id' => '',
), $atts));
if(is_user_logged_in() && is_numeric($product_id)){
$user_id = get_current_user_id();
$check = wc_customer_bought_product('',$user_id,$product_id);
if($check){
echo apply_filters('the_content',$content);
}else{
$product = get_product( $product_id );
if(is_object($product)){
$link = get_permalink($product_id);
$check=vibe_get_option('direct_checkout');
if(isset($check) && $check)
$link.='?redirect';
$price_html = str_replace('class="amount"','class="amount" itemprop="price"',$product->get_price_html());
echo '<div class="message info">'.
sprintf(__('You do not have access to this content. <a href="%s" class="button"> Puchase </a> content for %s','vibe-shortcodes'),$link,$price_html).
'</div>';
}else{
echo '<div class="message info">'.__('You do not have access to this content','vibe-shortcodes').'</div>';
}
}
}else{
$product = get_product( $product_id );
if(is_object($product)){
$link = get_permalink($product_id);
$check=vibe_get_option('direct_checkout');
if(isset($check) && $check)
$link.='?redirect';
$price_html = $product->get_price_html();
echo '<div class="message info">'.
sprintf(__('You do not have access to this content. <a href="%s" class="button"> Puchase </a> content for %s','vibe-shortcodes'),$link,$price_html).
'</div>';
}else{
echo '<div class="message info">'.__('You do not have access to this content','vibe-shortcodes').'</div>';
}
}
return $return;
}
add_shortcode('sell_content', 'vibe_sell_content');
}