Home › Forums › WoodMart support forum › Buy Now Button
Buy Now Button
- This topic has 7 replies, 2 voices, and was last updated 5 months, 3 weeks ago by Aizaz Imtiaz Awan.
-
AuthorPosts
-
June 21, 2024 at 9:29 am #574322
14kaboParticipantHello i want to change the name and url of button “Buy now”
i used loco translate plugin and change it didn’t work
for change url i go to theme setting > single product > buy now i just see “checkout and cart page” only
thanks .June 21, 2024 at 1:41 pm #574443
Aizaz Imtiaz AwanKeymasterHello,
Please try to add the code below in the functions.php file in your child theme.
/* Create Buy Now Button dynamically after Add To Cart button */ 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 ); // run only on simple products if( $product->is_type( 'simple' ) ){ echo '<a href="https://example.com?add-to-cart='.$current_product_id.'" class="buy-now button">Purchase Now</a>'; } } add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart' );
Replace https://example.com with the URL you want the button to link to and Purchase Now with the desired button text. This code will dynamically generate the “Buy Now” button with the specified link and text for simple products.
Best Regards.
June 21, 2024 at 2:58 pm #574509
14kaboParticipanthello,
i did it
and it added new button like in screen shot
also its appear in simple products only … i have grouped products didn’t appear in it there is screen shot alsoAttachments:
You must be logged in to view attached files.June 21, 2024 at 4:28 pm #574543
Aizaz Imtiaz AwanKeymasterHello,
Please remove the previous code and try to add this code.
function sbw_wc_add_buy_now_button_single() { global $product; $custom_button_text = 'Purchase Now'; // Custom button text printf( '<button id="sbw_wc-adding-button" type="submit" name="sbw-wc-buy-now" value="%d" class="single_add_to_cart_button buy_now_button button alt">%s</button>', $product->get_ID(), esc_html__( $custom_button_text, 'sbw-wc' ) ); } add_action( 'woocommerce_after_add_to_cart_button', 'sbw_wc_add_buy_now_button_single' ); /*** Handle for click on buy now ***/ function sbw_wc_handle_buy_now() { if ( !isset( $_REQUEST['sbw-wc-buy-now'] ) ) { return false; } WC()->cart->empty_cart(); $product_id = absint( $_REQUEST['sbw-wc-buy-now'] ); $quantity = absint( $_REQUEST['quantity'] ); if ( isset( $_REQUEST['variation_id'] ) ) { $variation_id = absint( $_REQUEST['variation_id'] ); WC()->cart->add_to_cart( $product_id, 1, $variation_id ); } else { WC()->cart->add_to_cart( $product_id, $quantity ); } // Redirect to custom URL $custom_url = 'https://example.com/custom-checkout'; // Custom URL wp_safe_redirect( $custom_url ); exit; } add_action( 'wp_loaded', 'sbw_wc_handle_buy_now' );
Best Regards.
June 21, 2024 at 6:37 pm #574561
14kaboParticipantHello,
Please check screenshot + when i click on it (like add to cart) no redirect to custom url
Attachments:
You must be logged in to view attached files.June 22, 2024 at 9:41 am #574605
Aizaz Imtiaz AwanKeymasterHello,
Sorry to hear about the inconvenience. Kindly, please share your Site WP-ADMIN Login details in the Private Content field so that we can check this concern on your Site and help you out accordingly.
Best Regards.
June 22, 2024 at 10:54 am #574624
14kaboParticipantHello please check
June 22, 2024 at 3:30 pm #574691
Aizaz Imtiaz AwanKeymasterHello,
You are adding the custom url. You can do it without custom code. Navigate to layouts > Edit Single Product layout with Elementor and add the button widget next to the add to cart and add the custom link.
https://ibb.co/sqBznmFBest Regards.
-
AuthorPosts
- You must be logged in to create new topics. Login / Register