Hi, i have used this code to use woocommerce checkout instead of pmpro checkout.
However if the cart is empty the user is unable to finish the checkout. The code is only working if there is an item in the cart already*
add_action('template_redirect','pmpro_woocommerce_redirect_checkout');
function pmpro_woocommerce_redirect_checkout(){
$id = get_option('pmpro_checkout_page_id');
global $post;
if($post->ID == $id && !empty($_REQUEST['level'])){
global $wpdb;
$product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %d",'_membership_product_level',$_REQUEST['level']));
if(!empty($product_id)){
$checkout_url = WC()->cart->get_checkout_url();
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 );
wp_redirect( $checkout_url);
}else{
// if no products in cart, add it
WC()->cart->add_to_cart( $product_id );
wp_redirect( $checkout_url);
}
exit();
}
}
}
This reply has been marked as private.
Okay please make sure that in woocommerce settings "Redirect to cart page after successful additon" enabled from wp-admin-> woocommerce-> settings -> products -> display :
http://prntscr.com/e2zuoc
Second thing that you need to make sure is your membership level should be connected to only one product ,not in multiple product.This instruction is also mentioned in the tip .
Redirect to cart page after successful additon is enabled
and it is connected to only one product
still not working, it only works if there is already 1 product in the cart already
This reply has been marked as private.
This reply has been marked as private.
This reply has been marked as private.
solved it
it was wpengine Varnish caching layer
excluded cart/checkout pages on its working now
Thanks for confirming .
Marking as resolved and closing the topic .