Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Last active March 16, 2021 08:01
Show Gist options
  • Save MrVibe/800a89ba6195ab5e2a84d914fa6a009b to your computer and use it in GitHub Desktop.
Save MrVibe/800a89ba6195ab5e2a84d914fa6a009b to your computer and use it in GitHub Desktop.
Direct checkout other themes
add_filter('wplms_course_non_loggedin_user',function($link){
$link = str_replace('">','?redirect">',$link);
return $link;
});
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();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment