cocart-headless / cocart-get-cart-enhanced

This free add-on enhances the cart response by returning additional data for both the cart and the items added to it.
https://wordpress.org/plugins/cocart-get-cart-enhanced/
GNU General Public License v3.0
6 stars 2 forks source link

Parent ID for variable product is 0. #2

Closed anarepa closed 3 years ago

anarepa commented 3 years ago

I think there is a bug in this code.
The parent Id for variable product is 0. The condition should remove 'variable'. Only a variation has a parentID. Correct me if I am wrong. Thanks!

public function get_product_slug( $object ) {
            $product_type = $object->get_type();

            if ( 'variable' === $product_type || 'variation' === $product_type ) {
                $product = wc_get_product( $object->get_parent_id() );

                $product_slug = $product->get_slug();
            } else {
                $product_slug = $object->get_slug();
            }

            return $product_slug;
        }
seb86 commented 3 years ago

You are correct @anarepa Feel free to send a PR and I will credit you as a contributor.