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

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

报告相同问题?

悬赏问题

  • ¥40 图书信息管理系统程序编写
  • ¥15 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题