I am replaced add to cart button with the buy now button. Now I want to add content after the buy now button.
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() . '" 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.
CodePudding user response:
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 >your content</div>';
}
CodePudding user response:
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.'" >'.$button_text.'</a>';
endif;
}