Remove variation attribute drop downs in WooCommerce

£可爱£侵袭症+ 提交于 2019-12-02 20:09:04

问题


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).



来源:https://stackoverflow.com/questions/48188738/remove-variation-attribute-drop-downs-in-woocommerce

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