[ 'label' => __('Temperatuur', 'siti-wash-instructions'), 'term_key' => 'lb_wash_temp', 'product_key' => '_lb_wash_temp', 'icon' => '🌡️', 'options' => [ '' => __('Geen advies', 'siti-wash-instructions'), 'cold' => __('Koud wassen (max 20°C)', 'siti-wash-instructions'), '30h' => __('30°C handwas', 'siti-wash-instructions'), '30' => __('30°C fijnwas', 'siti-wash-instructions'), '40' => __('40°C normaal', 'siti-wash-instructions'), '60' => __('60°C intensief', 'siti-wash-instructions'), 'hand' => __('Alleen handwas', 'siti-wash-instructions'), ], ], 'dryer' => [ 'label' => __('Droger', 'siti-wash-instructions'), 'term_key' => 'lb_wash_dryer', 'product_key' => '_lb_wash_dryer', 'icon' => '🌀', 'options' => [ '' => __('Geen advies', 'siti-wash-instructions'), 'no' => __('Niet in de droger', 'siti-wash-instructions'), 'low' => __('Alleen lage stand', 'siti-wash-instructions'), 'yes' => __('Droger toegestaan', 'siti-wash-instructions'), ], ], 'iron' => [ 'label' => __('Strijken', 'siti-wash-instructions'), 'term_key' => 'lb_wash_iron', 'product_key' => '_lb_wash_iron', 'icon' => '🧺', 'options' => [ '' => __('Geen advies', 'siti-wash-instructions'), 'no' => __('Niet strijken', 'siti-wash-instructions'), 'low' => __('Lage temperatuur', 'siti-wash-instructions'), 'med' => __('Gemiddelde temperatuur', 'siti-wash-instructions'), 'high' => __('Hoge temperatuur', 'siti-wash-instructions'), ], ], 'bleach' => [ 'label' => __('Bleken', 'siti-wash-instructions'), 'term_key' => 'lb_wash_bleach', 'product_key' => '_lb_wash_bleach', 'icon' => '🫧', 'options' => [ '' => __('Geen advies', 'siti-wash-instructions'), 'no' => __('Niet bleken', 'siti-wash-instructions'), 'yes' => __('Alleen zuurstofbleekmiddel', 'siti-wash-instructions'), ], ], ]; } public static function register_brand_hooks(): void { $tax = self::TAXONOMY; add_action("{$tax}_add_form_fields", [__CLASS__, 'render_brand_add_form']); add_action("{$tax}_edit_form_fields", [__CLASS__, 'render_brand_edit_form'], 10, 2); add_action("created_{$tax}", [__CLASS__, 'save_brand_fields']); add_action("edited_{$tax}", [__CLASS__, 'save_brand_fields']); } public static function render_brand_add_form($taxonomy): void { foreach (self::fields() as $field) { self::render_brand_field('', $field); } } public static function render_brand_edit_form($term, $taxonomy): void { foreach (self::fields() as $field) { $value = (string) get_term_meta($term->term_id, $field['term_key'], true); ?>
__('Wasadvies', 'siti-wash-instructions'), 'target' => 'lb_wash_advice_panel', 'class' => ['lb-wash-advice-tab', 'show_if_simple', 'show_if_variable', 'show_if_grouped', 'show_if_external'], 'priority' => 66, ]; return $tabs; } public static function render_product_panel(): void { global $post; ?>
$field) { $product_value = get_post_meta($post->ID, $field['product_key'], true); $options = ['inherit' => __('Volg merk (standaard)', 'siti-wash-instructions')] + $field['options']; woocommerce_wp_select([ 'id' => $field['product_key'], 'label' => $field['label'], 'value' => $product_value !== '' ? $product_value : 'inherit', 'options' => $options, 'desc_tip' => false, 'description' => __('Kies hier om het merkadvies te overschrijven.', 'siti-wash-instructions'), ]); } ?>
$field) { $value = get_post_meta($product_id, $field['product_key'], true); if ($value === '' || $value === 'inherit') { $value = self::get_brand_value($product_id, $field['term_key']); } if ($value && isset($field['options'][$value])) { $result[$field_key] = [ 'label' => $field['label'], 'text' => $field['options'][$value], 'icon' => $field['icon'], ]; } } return $result; } private static function get_brand_value(int $product_id, string $meta_key): string { $terms = get_the_terms($product_id, self::TAXONOMY); if (empty($terms) || is_wp_error($terms)) { return ''; } foreach ($terms as $term) { $value = get_term_meta($term->term_id, $meta_key, true); if ($value !== '') { return (string) $value; } } return ''; } public static function render_frontend_block(bool $echo = true, $product = null): string { if ($product === null) { global $product; } if (!$product instanceof WC_Product) { return ''; } $output = self::build_wash_markup($product); if ($echo && $output !== '') { echo $output; } return $output; } private static function build_wash_markup(WC_Product $product): string { $data = self::get_product_advice($product->get_id()); if (empty($data)) { return ''; } ob_start(); static $printed_styles = false; if (!$printed_styles) { $printed_styles = true; ?>
🧼