Product additionnal buttons in Woocommerce

筅森魡賤 提交于 2019-12-08 06:08:53

问题


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:


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.



来源:https://stackoverflow.com/questions/52912647/product-additionnal-buttons-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!