Sell unit content as product using the following shortcode:
Why We Need This Shortcode
This is a general question asked by our users that why do we need this shortcode to sell the unit content.
Use case:
You have a course which is free but you want to sell some of the contents of that course. Then, in this case, no need to associate the whole course with a woocommerce product when you want only a single unit to sell.
Please check the video of unit sell content shortcode when unit lock is enabled
https://screencast-o-matic.com/watch/cF60XqYACh
Note : No longer required as it is built in WPLMS v 2.3+
Add the following code in child theme functions.php or in customizer_class.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
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'); } |