douhan5547 2018-10-21 06:20
浏览 208
已采纳

Woocommerce中的产品附加按钮

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条回答 默认 最新

  • duanjia4220 2018-10-21 07:39
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog