Filter the shown items of a script based custom field by category in woocommerce


I created a cutom field for the Woocommerce check out page with several items:

add_filter( 'woocommerce_after_order_notes', 'haendler_location_checkout_field' );
function haendler_location_checkout_field( $checkout ) {

woocommerce_form_field( 'haendler_location', array(
    'type'        => 'select',
    'class'       => array('my-field-class form-row-wide'),
    'label'       => __('Händler', 'woocommerce'),
    'required'    => true,
    'options'     => array(
        ''   => __('Bitte wählen Sie einen Händler aus', 'woocommerce' ),
            'ACC' => __('ACC KG (Hamburg) VAN', 'woocommerce' ),
            'SOMMERDAMM' => __('Autohaus Sommerdamm (Worms) VAN', 'woocommerce' ),
            'EMR' => __('EMR Campers (Stuttgart) WOMO', 'woocommerce' ),
            'THOMA' => __('Eurocar Thoma (Dueren) WOMO', 'woocommerce' ),

            'WVS' => __('WVS Wohnmobilvermietung (Saarlouis) VAN & WOMO', 'woocommerce' ),
            'OWL' => __('Wohnmobil Zentrum OWL (Verl) VAN & WOMO', 'woocommerce' ),
), $checkout->get_value( 'haendler_location' ));        

Now I would like to show only special items depending on catagory of the products in the cart:

  • retailers which sell vans or vans & womos if only vans are in the cart
  • retailers which sell womos or womos & vans if only womos are in the cart
  • retailers which sell womos & van if vans and womos are in the cart

I tried a lot of variations in the code to realize this but without success. So I hope somebody can helpt me. It would be great.

, , , , Helli Benz 3 years 2020-08-19T10:10:30-05:00 0 Answers 43 views 0

Leave an answer