0

I am making a website in Wordpress and created a custom shortcode for loading the products. That is working fine, however when clicking the add the cart button, if redirects me to the cart page, where it should just add the product to the cart.

Hope someone dan help.

// Add to Cart button.
$output .= '<div class="add-to-cart-button">';
$output .= '<form action="' . esc_url(wc_get_cart_url()) . '" method="post" enctype="multipart/form-data" class="cart">';
$output .= sprintf(
    '<input type="hidden" name="add-to-cart" value="%d">',
    get_the_ID()
);

$output .= sprintf(
    '<button type="submit" class="single_add_to_cart_button button alt">%s</button>',
    esc_html__('Add to Cart', 'kaon-child')
);
$output .= '</form>';
$output .= '</div>';
1
  • Your form's action will take you to esc_url(wc_get_cart_url()), unless you subvert it with some JavaScript. You should check with the plugin's support team about this, though; third-party plugin support is off topic here.
    – Pat J
    Jan 2 at 23:24

0

Your Answer

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