-1

What I'm trying to accomplish is when the checkout page is accessed with certain get arguments a product to be added to the cart.

function my_custom_function() {
  if ( $_SERVER['REQUEST_URI'] == 'checkout/?some=argv' ) {
    WC()->cart->add_to_cart( 90759, 1 );
  }
}
add_action( 'init', 'my_custom_function', 7 );

I tried this but when I access the checkout page it's not added to the cart and i get redirected to the cart page.

1 Answer 1

0

I've figured it out

function my_custom_function() {
    global $woocommerce;
  if ( $_SERVER['REQUEST_URI'] == '/checkout/?a=b' ) {
    $woocommerce->cart->add_to_cart( 90759, 1 );
    // exit;
  }
}
add_action( 'init', 'my_custom_function', 7 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.