Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************************************************************
- *Add this on functions.php of your WordPress
- *********************************************************************************************/
- function add_content_after_addtocart() {
- // 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( 'simple' ) )
- ?>
- <script>
- 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();
- });
- });
- });
- </script>
- <?php
- {
- echo '<a href="'.$checkout_url.'?add-to-cart='.$current_product_id.'" class="single_add_to_cart_button button custom-checkout-btn alt">Buy Instant</a>';
- }
- }
- add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement