1

In Woocommerce, how do I add a "Continue" button inked to the the product page just after?

And inside the product page how to add a checkout button just under the add to cart button?

Any help is appreciated.

1 Answer 1

0

The following code will:

  • In woocommerce archive pages: Add an additional button "Continue" linked to the product (for simple products)
  • In single product pages: Add an additional button linked to checkout page.

The code:

// Archives pages: Additional button linked to the product
add_action( 'woocommerce_after_shop_loop_item', 'loop_continue_button', 15 );
function loop_continue_button(){
    global $product;

    if( $product->is_type('simple') ){
        $link = $product->get_permalink();
        $text = __("Continue", "woocommerce");

        echo '<a href="' . $link . '" class="button alt" style="margin-top:10px;">' . $text . '</a>';
    }
}

// Single product pages: Additional button linked to checkout
add_action( 'woocommerce_single_product_summary', 'product_additional_checkout_button', 1 );
function product_additional_checkout_button() {
    global $product;

    // For variable product types
    if( $product->is_type( 'variable' ) ) {
            add_action( 'woocommerce_single_product_summary', 'custom_checkout_button', 21 );
    }
    // For all other product types
    else {
        add_action( 'woocommerce_single_product_summary', 'custom_checkout_button', 31 );
    }
}

function custom_checkout_button() {
    $link = wc_get_checkout_url();
    $text = __("Proceed to checkout", "woocommerce");
    echo '<a href="' . $link . '" class="button alt" style="margin-bottom:14px;">' . $text . '</a>';
}

Code goes in function.php file of your active child theme (or active theme). Tested and work.

enter image description here

enter image description here

5
  • 's this the link to my developing site check how it displayed box5202.temp.domains/~iboconne Oct 22, 2018 at 12:20
  • @Lexissmigz because you need to add the necessary CSS rules to get the right display. Oct 22, 2018 at 13:38
  • Could you be of help ?? Oct 22, 2018 at 13:42
  • @Lexissmigz I don't do any theming or styling sorry... just pure coding. Oct 22, 2018 at 13:45
  • is there a way i can contact you through your mail? Oct 29, 2018 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.