Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Currently I am trying to create multiple check-out pages within my WordPress WooCommerce webshop. I created a shortcode to do the following:

  • Empty the cart
  • Add a product to the cart
  • Display the checkout form

The expected behaviour: The checkout form should display, with having the added product in the cart.

Found error: The 'Place order' button is redirecting to the front page. Most likely this is due to the fact that the page on which the shortcode is used is not set as the 'checkout page'. That probably results in WooCommerce not loading the correct files.

I already tried to use the WooCommerce One Page Checkout plug-in, and I tried to define WOOCOMMERCE_CHECKOUT to true (in multiple ways).

My current code is as follows:

function webob_single_checkout( $atts ){

add_filter('woocommerce_is_checkout', '__return_true');

$atts = shortcode_atts( array(
    'id' => 392
), $atts );

$pId = $atts['id'];

//Remove all products from cart
global $woocommerce;
$woocommerce->cart->empty_cart();

//Add product to cart
$woocommerce->cart->add_to_cart($pId);

return do_shortcode('[woocommerce_checkout]');

}
add_shortcode( 'webob_single_checkout', 'webob_single_checkout' );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
225 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...