Need to add Custom checkout button on single product page
-
Hi,
I need to add custom checkout button near ‘Add to Cart’ button in single product page.
i used the following code and button is showing in product page. But the issue is when we selects the variations and clicks custom checkout button, shows the error ‘Please choose product options…’ in the checkout page. i think variations are not set.
Please help with this jsfunction add_content_after_addtocart() {
global $woocommerce;
// get the current post/product ID
$current_product_id = get_the_ID();// get the product based on the ID
$product = wc_get_product( $current_product_id );// get the ‘Checkout Page’ URL
$checkout_url = WC()->cart->get_checkout_url();// run only on simple products
if( $product->is_type( ‘variable’ ) ){?>
jQuery(function($) {
// if our custom button is clicked
$(‘.custom-checkout-btn’).on(‘click’, function() {// get the value of the ‘href’ attribute
$(this).attr(‘href’, function() {
// return the ‘href’ value + the string ‘&quantity=’ + the current selected quantity number
return this.href + ‘&quantity=’ + $(‘input.qty’).val() + gh;
});});
$( ‘.variations_form’ ).on( ‘woocommerce_variation_select_change’, function () {
alert( ‘Options changed’ );
} );
});
<?php
echo '
‘;
?>
is_type( ‘simple’ ) ){
echo ‘
‘;
}}
add_action( ‘woocommerce_after_add_to_cart_button’, ‘add_content_after_addtocart’ ); -
Hi there,
Could you please let us know your website address?
Please note that we are only able to provide assistance to the users whose site is hosted here at WordPress.com.
If your site is hosted elsewhere you can post your questions on the support forum for self-hosted sites on WordPress.org:
https://wordpress.org/support/forums/ -
I see you have already posted in the WooCommerce support forum: https://wordpress.org/support/topic/need-to-add-custom-checkout-button-on-single-product-page/
Hope you are able to find a fix soon :)
- The topic ‘Need to add Custom checkout button on single product page’ is closed to new replies.