Remove variation attribute drop downs in WooCommer

2020-05-06 12:11发布

问题:

I am trying to remove the variations dropdown from a single product page, I have successfully removed the summary using...

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 20 );

But I have been unable to find a similar snippet to remove the dropdown. anyone have an example I can see?

回答1:

To remove the product excerpt you should normally use woocommerce_template_single_excerpt (with a priority of 20) like:

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );

To remove (for variable products) the attribute dropdowns, the quantity field and the add to cart button you should use woocommerce_template_single_add_to_cart (with a priority of 30) like:

add_action( 'woocommerce_single_product_summary', 'removing_variable_add_to_cart_template', 3 );
function removing_variable_add_to_cart_template(){
    global $product;

    // Only for variable products
    if( $product->is_type( 'variable' ) ){
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
}

Is not possible to use remove_action() if you wish to remove just the dropdowns without removing quantity field and add-to-cart button.

If it's the case you will be obliged to manipulate/override the template itself…
See this documentation: Template structure & Overriding templates via a theme

The attribute dropdowns from variable products are located in the template WooCommerce template single-product/add-to-cart/variable.php.

You will be oblige to insert an IF statement with the necessary condition that will feet your needs (at line 34 just after the ELSE statement in this template).