【问题标题】:Product additionnal buttons in WoocommerceWoocommerce 中的产品附加按钮
【发布时间】:2019-03-25 13:01:48
【问题描述】:

在 Woocommerce 中,如何在紧随其后的产品页面上添加一个“继续”按钮?

在产品页面内如何在添加到购物车按钮下方添加结帐按钮?

感谢任何帮助。

【问题讨论】:

    标签: php wordpress button woocommerce product


    【解决方案1】:

    以下代码将:

    • 在 woocommerce 归档页面中:添加一个链接到产品的附加按钮“继续”(对于简单产品)
    • 在单个产品页面中:添加一个链接到结帐页面的附加按钮。

    代码:

    // 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>';
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试和工作。

    【讨论】:

    • 这是我的开发站点的链接,检查它的显示方式box5202.temp.domains/~iboconne
    • @Lexissmigz 因为您需要添加必要的 CSS 规则才能获得正确的显示。
    • 你能帮忙吗??
    • @Lexissmigz 我不做任何主题或造型对不起......只是纯粹的编码。
    • 我可以通过您的邮件联系您吗?
    猜你喜欢
    • 2020-11-16
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-21
    • 2018-12-16
    • 2018-04-23
    相关资源
    最近更新 更多