lundi 12 octobre 2020

If specific product is purchased, then checkbox on form must be set to checked

My coding is not very good. I have managed to get this far, but am not sure how to work with checkboxes. If a specific product is purchased, i am needing the checkbox in the form on the next page to be set to checked automatically when the user is redirected to the page.

This is my code and the check for product is working fine and redirecting to the page, as it should.

 add_action( 'woocommerce_thankyou', 'redirect_product_based', 1 ); 
    function redirect_product_based ( $order_id ){
                $order = wc_get_order( $order_id );
            
                foreach( $order->get_items() as $item ) {
                    if ( $item['product_id'] == 370 ) {
 checked(1, get_option('checkbox1'), true);
                         wp_redirect( 'https://website-name.co.za/thank-you/' );
                    
                    }
                }        
    }

Any assistance would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire