Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Last active October 28, 2021 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrVibe/f01c5ca112e2d04aa73c897ae0fa6cbb to your computer and use it in GitHub Desktop.
Save MrVibe/f01c5ca112e2d04aa73c897ae0fa6cbb to your computer and use it in GitHub Desktop.
Direct checkout WPLMS pluign
add_action('template_redirect',function(){
if( is_single() && get_post_type() == 'product' && isset($_GET['redirect'])){
global $woocommerce;
$found = false;
$product_id = get_the_ID();
$courses = vibe_sanitize(get_post_meta(get_the_ID(),'vibe_courses',false));
if(isset($courses) && is_array($courses) && count($courses)){
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id == $product_id )
$found = true;
}
// if product not found, add it
if ( ! $found )
WC()->cart->add_to_cart( $product_id );
$cart_url = esc_url( wc_get_cart_url() );
wp_redirect( $cart_url);
}else{
WC()->cart->add_to_cart( $product_id );
$cart_url = esc_url( wc_get_cart_url() );
wp_redirect( $cart_url);
}
exit();
}
}
});
add_filter('vibe_get_option',function($return,$field){
if($field == 'direct_checkout'){
$return = 1;
}
return $return;
},10,2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment