Home Forums WoodMart support forum how to add buy now button beside add to cart button on homescreen products

how to add buy now button beside add to cart button on homescreen products

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #562859

    sohoztech.business
    Participant

    i need to add buy now or order now button beside add to card to every where not only on single product page , it need to be avilabe on both desktop and mobile site , and need Products columns on mobile need to 3/4 not 2 only..i am not a developer so plese sent any custom css if it fix my problem.my business competitors website have this button on his website on mobile view, customar can go to his website home page and directly chose to oder now/buy now or add to cart button,customer doesnt need to go single product page for that

    Attachments:
    You must be logged in to view attached files.
    #562990

    Hello,

    Unfortunately, “Buy now” button cannot be added to the product archive pages. It can be added to a single product only.

    Here is the manual:
    https://xtemos.com/docs-topic/buy-now-button/

    Alternatively, try to use the quick feature of our theme. Navigate to Theme Settings > Shop > Variable Products > Quick Shop.

    Best Regards.

    #563009

    sohoztech.business
    Participant

    how my competitors do that?is there any custom ccs for that?

    #563068

    Hello,

    Please try to add the code below in the functions.php file in your child theme.

    // Add Buy Now button on single product page
    function add_buy_now_button_on_single_product_page() {
        // 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);
        
        // get the "Checkout Page" URL
        $checkout_url = WC()->cart->get_checkout_url();
        
        // check if product type is simple or variable
        if ($product->is_type('simple') || $product->is_type('variable')) {
            echo '<a href="' . $checkout_url . '?add-to-cart=' . $current_product_id . '" class="buy-now button">Buy Now</a>';
        }
    }
    
    add_action('woocommerce_after_add_to_cart_button', 'add_buy_now_button_on_single_product_page');
    
    // Add Buy Now button on shop page
    function add_buy_now_button_on_shop_page() {
        // get the product ID
        $product_id = get_the_ID();
        
        // get the product based on the ID
        $product = wc_get_product($product_id);
        
        // get the "Checkout Page" URL
        $checkout_url = WC()->cart->get_checkout_url();
        
        // check if product type is simple or variable
        if ($product->is_type('simple') || $product->is_type('variable')) {
            echo '<a href="' . $checkout_url . '?add-to-cart=' . $product_id . '" class="buy-now button">Buy Now</a>';
        }
    }
    
    add_action('woocommerce_after_shop_loop_item', 'add_buy_now_button_on_shop_page');

    Best Regards.

    #563690

    sohoztech.business
    Participant

    thank you so much AZIZ IMTIAZ AWAN ,i applyed your code but it only work on simple product not on veriable product , if i click buy now button on veriable product its redirect me to ceckout but the proble is its not attach that product and in ceckout fild its show empty. and your code also include buy now buton on single product page too but woodmart already include buy now button on single product page, so please help me to remove that duble buynow button too on the code,but most importat thing is that code need to be working on veriable products too on shop page or home product archive page too.

    #563824

    Hello,

    Please remove the previous code and add the following code in the functions.php file in your child theme.

    function add_buy_now_button_on_shop_page() {
        // get the product ID
        $product_id = get_the_ID();
        
        // get the product based on the ID
        $product = wc_get_product($product_id);
        
        // get the "Checkout Page" URL
        $checkout_url = WC()->cart->get_checkout_url();
        
        // check if product type is simple or variable
        if ($product->is_type('simple')) {
            echo '<a href="' . $checkout_url . '?add-to-cart=' . $product_id . '" class="buy-now button">Buy Now</a>';
        } elseif ($product->is_type('variable')) {
            echo '<a href="' . get_permalink($product_id) . '" class="buy-now button">Buy Now</a>';
        }
    }
    
    add_action('woocommerce_after_shop_loop_item', 'add_buy_now_button_on_shop_page');

    Best Regards.

    #564112

    sohoztech.business
    Participant

    thanks agin Aizaz Imtiaz Awan ,but it fix little bit my problem ,for now after clicking buy now button goes to cart page for sample product too , i dont want to go cart page for simpe product ,go cart page only if product has veriable like size and color to choose , for simple product it need to go direct checkout page which product i click and it should clean my cart item too,please help me with that code ..and alos how to change buy now button color ,size,border etc . i attach screenshot for color change in buy now button too,now its look ugly to me.i need to change according to my theme button or add to cart button color ..plese visit my website for further checking https://www.sohoztech.com

    Attachments:
    You must be logged in to view attached files.
    #564180

    Hello,

    Please remove the previous code and add the following code in the functions.php file in your child theme.

    function add_buy_now_button_on_shop_page() {
        // Get the product ID
        $product_id = get_the_ID();
        
        // Get the product based on the ID
        $product = wc_get_product($product_id);
        
        // Get the "Checkout Page" URL
        $checkout_url = wc_get_checkout_url();
        
        // Check if product type is simple or variable
        if ($product->is_type('simple')) {
            // Directly add to cart and redirect to checkout
            echo '<a href="' . $checkout_url . '?add-to-cart=' . $product_id . '" class="buy-now button">Buy Now</a>';
        } elseif ($product->is_type('variable')) {
            // Redirect to the product page for variable products
            echo '<a href="' . get_permalink($product_id) . '" class="buy-now button">Buy Now</a>';
        }
    }
    
    add_action('woocommerce_after_shop_loop_item', 'add_buy_now_button_on_shop_page');

    To style the button, you can add custom CSS in Theme Settings > Custom CSS:

    .buy-now.button {
        background-color: #ff6600; /* Change button background color */
        color: #fff; /* Change button text color */
        padding: 10px 20px; /* Change button padding */
        border-radius: 5px; /* Add border radius */
        border: 2px solid #ff6600; /* Add border */
        text-decoration: none; /* Remove underline */
    }

    Best Regards.

    #564209

    sohoztech.business
    Participant

    thnaks agin Aizaz Imtiaz Awan but i feel very sorry for you to say that this code still not working for me ,, it seams it does not change any thing, for single product when i press buy now button i doesn’t redirect me to checkout page , it goes to me in cart page i don’t why, if you want further checking i can give you my wordpress acess ,i applyed the code if you visit my website and chose any simple product . i provide the temporary acess link of my website,, one thing after every change you need to go to top waprocket icon and clear and preload cashes to see visable changes

    #564326

    Hello,

    Sorry to say such modification requires complicated code customization which is not covered by our support.

    You need to find a third party plugin to achieve more functionality that best suits you. We have not tested such kinds of plugins, so we don’t have any detailed suggestions.

    Best Regards.

    #564558

    sohoztech.business
    Participant

    hi, Aizaz Imtiaz Awan thanks for the support,i want to inform you that your code was working from the beginning but the problem was wocommerce settings page which redirect add to cart to cart page , after lots of checking i fix that and now its working
    Can you help me with one more thing that ,previously i installed a plugin for same kinda thing like buy now button, for now i don’t need that plugin because of your code but i am missing something from that plugin is that when i click buy now button it has an option that it will erese my previous add to cart item and only show me that single product that i just click for buy now, that setting was optional on the plugin setting ,so user can either enable or disable it , for now can you please add this functionality too on your awesome code.so that i can have 2 kinds of code and i can use any of them whenever i want that option as like that plugin.
    pleaase saw the picture for further understanding what i mean

    Attachments:
    You must be logged in to view attached files.
    #564660

    Hello,

    Sorry to say it requires customization and beyond our support policy. Additional code customizations are out of our theme support scope.

    Hope you can understand!

    Best Regards.

Viewing 12 posts - 1 through 12 (of 12 total)