Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /********************************************************************************************
  2. *Add this on functions.php of your WordPress
  3. *********************************************************************************************/
  4.  
  5. function add_content_after_addtocart() {
  6.  
  7. // get the current post/product ID
  8. $current_product_id = get_the_ID();
  9.  
  10. // get the product based on the ID
  11. $product = wc_get_product( $current_product_id );
  12.  
  13. // get the "Checkout Page" URL
  14. $checkout_url = WC()->cart->get_checkout_url();
  15.  
  16. // run only on simple products
  17. if( $product->is_type( 'simple' ) )
  18. ?>
  19. <script>
  20. jQuery(function($) {
  21.  
  22. // if our custom button is clicked
  23. $(".custom-checkout-btn").on("click", function() {
  24.  
  25. // get the value of the "href" attribute
  26. $(this).attr("href", function() {
  27. // return the "href" value + the string "&quantity=" + the current selected quantity number
  28. return this.href + '&quantity=' + $('input.qty').val();
  29. });
  30.  
  31. });
  32. });
  33. </script>
  34. <?php
  35.  
  36. {
  37.  
  38. 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>';
  39. }
  40. }
  41. add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement