Adding Extra Add to cart button below product summary in Woocommerce

落爺英雄遲暮 提交于 2019-12-04 17:36:20

I have revisited your code a bit, and added a 2nd hooked function for variable products:

// For Simple products
add_action( 'woocommerce_single_product_summary', 'second_button_after_product_summary', 30 );
function second_button_after_product_summary() {
    global $product;

    if( ! $product->is_type( 'variable' ) )
        echo '<button type="submit" name="add-to-cart" value="'. esc_attr( $product->get_id() ).'" class="single_add_to_cart_button button alt">'. esc_html( $product->single_add_to_cart_text() ).'</button>';
}

// For Variable products
add_action( 'woocommerce_single_variation', 'second_button_single_variation', 30 );
function second_button_single_variation() {
    global $product;

    echo '<br>
        <button type="submit" class="single_add_to_cart_button button alt">'. esc_html( $product->single_add_to_cart_text() ).'</button>';
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

You will get this on variable products:

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