{"id":3524,"date":"2022-05-14T09:03:35","date_gmt":"2022-05-14T09:03:35","guid":{"rendered":"https:\/\/scriptfeeds.com\/blog\/?p=3524"},"modified":"2022-12-06T21:57:25","modified_gmt":"2022-12-06T21:57:25","slug":"add-buy-now-button-in-woocommerce-variable-product","status":"publish","type":"post","link":"https:\/\/scriptfeeds.com\/blog\/wordpress\/add-buy-now-button-in-woocommerce-variable-product\/","title":{"rendered":"How to add buy now button in WooCommerce Variable Product"},"content":{"rendered":"\n<p>WooCommerce has vast of customization by which web shop owner can build the online web shop the way they want. By default WooCommerce has &#8220;<strong>ADD TO CART<\/strong>&#8221; button on all products. In this article we going to guide you how you can add the &#8220;<strong>BUY NOW<\/strong>&#8221; button with the &#8220;<strong>ADD TO CART<\/strong>&#8221; button on single and variable WooCommerce products.<\/p>\n\n\n\n<p>But if you want to change&nbsp;<strong>\u201cADD TO CART\u201d<\/strong>&nbsp;button to&nbsp;<strong>\u201cADDED TO CART\u201d<\/strong> when product added in cart then you can<a href=\"https:\/\/scriptfeeds.com\/blog\/wordpress\/how-to-change-add-to-cart-text-if-a-product-is-in-cart-on-woocommerce\/\"> click here.<\/a><\/p>\n\n\n\n<h2 class=\"has-medium-font-size wp-block-heading\">Step by step guide to add &#8220;BUY NOW&#8221; button on Single and Variable Product. <\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create child theme and click on theme editor in &#8220;Appearance&#8221; option on left menu.<\/li>\n\n\n\n<li>Add the below code on your functions.php file. You can replace text &#8220;Buy now&#8221; which another text you want.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* Dynamic Button for Simple &amp; Variable Product *\/\n\n\/**\n * Main Functions\n*\/\n\nfunction sbw_wc_add_buy_now_button_single()\n{\n    global $product;\n    printf( '&lt;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\"&gt;%s&lt;\/button&gt;', $product-&gt;get_ID(), esc_html__( 'Buy Now', 'sbw-wc' ) );\n}\n\nadd_action( 'woocommerce_after_add_to_cart_button', 'sbw_wc_add_buy_now_button_single' );\n\n\n\n\/*** Handle for click on buy now ***\/\n\nfunction sbw_wc_handle_buy_now()\n{\n    if ( !isset( $_REQUEST&#91;'sbw-wc-buy-now'] ) )\n    {\n        return false;\n    }\n\n    WC()-&gt;cart-&gt;empty_cart();\n\n    $product_id = absint( $_REQUEST&#91;'sbw-wc-buy-now'] );\n    $quantity = absint( $_REQUEST&#91;'quantity'] );\n\n    if ( isset( $_REQUEST&#91;'variation_id'] ) ) {\n\n        $variation_id = absint( $_REQUEST&#91;'variation_id'] );\n        WC()-&gt;cart-&gt;add_to_cart( $product_id, 1, $variation_id );\n\n    }else{\n        WC()-&gt;cart-&gt;add_to_cart( $product_id, $quantity );\n    }\n\n    wp_safe_redirect( wc_get_checkout_url() );\n    exit;\n}\n\nadd_action( 'wp_loaded', 'sbw_wc_handle_buy_now' );\n\n\/* Dynamic Button for Simple &amp; Variable Product Closed *\/<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once code added, click on SAVE and check on website.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"has-medium-font-size wp-block-heading\">To change the &#8220;<strong>SELECT OPTIONS<\/strong>&#8221; text on shop page for variable products to &#8220;<strong>ADD TO CART<\/strong>&#8220;, you can follow below steps.<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add below code in same functions.php file.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter( 'woocommerce_product_single_add_to_cart_text', 'change_cart_button_text', 10, 2 );\nadd_filter( 'woocommerce_product_add_to_cart_text', 'change_cart_button_text', 10, 2 );\nfunction change_cart_button_text( $button_text, $product ) {\n    if ( $product-&gt;is_type( 'variable' ) )\n        $button_text = __('Buy Now', 'woocommerce');\n    return $button_text;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\" style=\"font-size:15px\">Above code is tested and Worked perfectly<\/p>\n\n\n\n<p>So that&#8217;s all you need to do to get WooCommerce works for you. Let us know how it works for you. For instant support ping us on whatsapp and comment in comment box.<\/p>\n\n\n\n<p>Happy coding!<\/p>\n\n\n<p>[caldera_form id=&#8221;CF60ca2e3ccf64f&#8221;]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WooCommerce has vast of customization by which web shop owner can build the online web shop the way they want. By default WooCommerce has &#8220;ADD TO CART&#8221; button on all products. In this article we going to guide you how you can add the &#8220;BUY NOW&#8221; button with the &#8220;ADD TO CART&#8221; button on single [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3393,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jnews-multi-image_gallery":[],"jnews_single_post":{"subtitle":"","format":"standard","video":"","gallery":"","source_name":"","source_url":"","via_name":"","via_url":"","override_template":"0","override":[{"template":"2","single_blog_custom":"","parallax":"1","fullscreen":"1","layout":"right-sidebar","sidebar":"default-sidebar","second_sidebar":"default-sidebar","sticky_sidebar":"1","share_position":"float","share_float_style":"share-monocrhome","show_share_counter":"1","show_view_counter":"1","show_featured":"1","show_post_meta":"1","show_post_author":"1","show_post_author_image":"1","show_post_date":"1","post_date_format":"default","post_date_format_custom":"Y\/m\/d","show_post_category":"1","show_post_reading_time":"0","post_reading_time_wpm":"300","show_zoom_button":"0","zoom_button_out_step":"2","zoom_button_in_step":"3","show_post_tag":"1","show_prev_next_post":"0","show_popup_post":"0","number_popup_post":"1","show_author_box":"0","show_post_related":"1","show_inline_post_related":"0"}],"override_image_size":"0","image_override":[{"single_post_thumbnail_size":"no-crop","single_post_gallery_size":"crop-500"}],"trending_post":"0","trending_post_position":"meta","trending_post_label":"Trending","sponsored_post":"0","sponsored_post_label":"Sponsored by","sponsored_post_name":"","sponsored_post_url":"","sponsored_post_logo_enable":"0","sponsored_post_logo":"","sponsored_post_desc":"","disable_ad":"0"},"jnews_primary_category":{"id":"","hide":""},"footnotes":""},"categories":[86,75],"tags":[217,218],"class_list":["post-3524","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-woocommerce","category-wordpress","tag-add-buy-now-button-in-woocommerce","tag-change-selected-option-to-buy-now-in-shop-page"],"_links":{"self":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/posts\/3524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/comments?post=3524"}],"version-history":[{"count":0,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/posts\/3524\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/media\/3393"}],"wp:attachment":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/media?parent=3524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/categories?post=3524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/tags?post=3524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}