0
votes

I currently need to sell a service with a subservice as option :

I have hadded a product panel & 2 meta for my option and its price.

If the user checks a checkbox in the product page, then the option is added to the cart page, the checkout page, thank you page, email and so on...

My problem is that i actually can update the initial product price in the product row, in cart & checkout tables but i need to :

1 : insert the additionnal service (the option) as a separate row in the checkout review order table and in the cart total table;

2 : dislay initial product price in the product row and udpdate only the total adding the option price in those 2 tables.

I'm really stuck here, any help would be great. Thank's

1

1 Answers

0
votes

OK, For the solution is quiet simple :

1 : add a product dropdow in admin tab to let user choose a linked product as a product option and register its ID a product meta;

2 : use woocommerce_add_to_cart_validation to intercept the option checkbox value from the product page and add the product option to cart from the initial product meta :

add_action( 'woocommerce_add_to_cart_validation', 'my_cart_validation' );
function my_cart_validation(){
    if( isset( $_POST['my-service-option'] ) ){
        WC()->cart->add_to_cart( get_post_meta( $_POST['add-to-cart'], 'service-option', true ) );
    }
}

3 : If the optional service is not supposed to be displayed in the shop loop, just remove it from the WC Query :

add_action( 'woocommerce_product_query', 'remove_optional_services' );
function remove_optional_services( $q ){
    $not_in = $q->get('post__not_in' );
    array_push( $not_in, 75 ); // you can grab your product ids from an option or whatever fits your needs
    $q->set('post__not_in', $not_in);
}

The good thing is you keep a simple control on taxes and prices with this method.