skip to Main Content

I am replaced add to cart button with the buy now button. Now I want to add content after the buy now button.

enter image description here

But I can’t find out an action or filter hook which works for this so far. This is the modified Buy Now button code.

function woocommerce_external_add_to_cart() {
global $product;
if ( ! $product->add_to_cart_url() ) return;
    echo '<p><a href="' . $product->add_to_cart_url() . '" class="single_add_to_cart_button button alt" target="_blank"><svg width="50" height="50" viewBox="0 0 50 50"><path
    d="M50,0V38.486a2.565,2.565,0,0,1-5.09.46l-.04-.46L44.861,9.359a.25.25,0,0,0-.425-.18L4.379,49.245a2.565,2.565,0,0,1-3.275.3l-.35-.3a2.565,2.565,0,0,1-.3-3.275l.3-.355L40.8,5.559a.25.25,0,0,0-.175-.43H11.509a2.565,2.565,0,0,1-2.525-2.1l-.04-.47a2.567,2.567,0,0,1,2.1-2.525L11.514,0Z"
    fill="currentColor"></path></svg>' . $product->single_add_to_cart_text() . '</a></p>';

I highly appreciate your help and suggestions in this regard.

2

Answers


  1. you can use this code for it

    add_action( 'woocommerce_after_add_to_cart_button', 'ak_add_content_after_addtocart_button' );
    function ak_add_content_after_addtocart_button() {
    
            echo '<div class="yourcontent">your content</div>';
    
    }
    
    Login or Signup to reply.
  2. this is direct checkout button

    add_action( 'woocommerce_after_add_to_cart_button', 'add_custom_addtocart_and_checkout' );
    function add_custom_addtocart_and_checkout() {
        global $product;
    
        $addtocart_url = wc_get_checkout_url().'?add-to-cart='.$product->get_id();
        $button_class  = 'single_add_to_cart_button button alt custom-checkout-btn';
        $button_text   = __("Buy Now", "woocommerce");
    
        if( $product->is_type( 'simple' )) :
        ?>
        <script>
        jQuery(function($) {
            var url    = '<?php echo $addtocart_url; ?>',
                qty    = 'input.qty',
                button = 'a.custom-checkout-btn';
    
            // On input/change quantity event
            $(qty).on('input change', function() {
                $(button).attr('href', url + '&quantity=' + $(this).val() );
            });
        });
        </script>
        <?php
        echo '<a href="'.$addtocart_url.'" class="'.$button_class.'">'.$button_text.'</a>';
        endif;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search