Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter sugud0r

    (@sugud0r)

    My issues was solved. For any those who have the same problem: When you create a custom producty type that inherits WC_Product_Variable you need to add woocommerce_add_to_cart_handler filter and return variable to tell WooCommerce the correct handler for your product type when the product is added to cart.

    Sample:

    
    /**
     * Set variable to handler add to cart
     *
     * @param string $handler
     * @param WC_Product $product
     * @return string
     */
    public static function set_correct_add_to_cart_handler( $handler, $product ) {
        if ( $product->is_type( 'your type' ) ) {
            $handler = 'the hanlder'; # variable, simple or grouped
        }
    
        return $handler;
    }
    
    add_filter( 'woocommerce_add_to_cart_handler', 'set_correct_add_to_cart_handler', 10, 2 );
    

    This also apply with simple or grouped products types (remember that you need to inherit the correct WC_Product_* class to create your custom product type).

    This behaviour is defined in woocommerce/includes/class-wc-form-handler.php line 769 for WooCommerce 4.4.1

    Also, you can define your own handler with the action 'woocommerce_add_to_cart_handler_' . $your_product_type, but I guess that you need to really know what you are doing.

Viewing 1 replies (of 1 total)