Woocommerce Grouped Products with Individual “Add

2019-07-13 17:15发布

问题:

I am trying to achieve the following:

On the grouped product detail page a Add to Cart button for each Individual item, also for each item the Individual price must be listed. I have seen the following can be done but i need to get it working in a grouped product;

Adding Woocommerce Add to Cart Button to related products and product listing

Any suggestions? Many Thanks!

回答1:

Heres how to make a hook work with grouped products in woocommerce. Just replace the add_action() below with any add_action or remove_action you want to use.

add_action('woocommerce_after_shop_loop_item', 'woo_custom_hook_function');

function woo_cusom_hook_function() {

    global $post;

    if (function_exists( 'get_product' )) {
        $product = get_product( $post->ID );

        if ($product->is_type( 'grouped' )) {
        // anything you hook into above will be run here for grouped products only.
        add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

        }
    }
}