Created
August 27, 2026 13:39
-
-
Save xlplugins/bf6d1b45f2a655b6539e896bcf7efafb to your computer and use it in GitHub Desktop.
Plakatdyr theme field Fk checkout compatibility 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: Plakatdyr — FunnelKit kundetype (MU) | |
| * Description: Theme customer-type radios on FunnelKit only; plakatdr CSS if missing; small #plakatdr-kundete override so WFACP’s global input[type=radio] rules do not break layout. Removes the EAN Bruger ID field. | |
| * Version: 1.7.2 | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| add_action( 'wfacp_checkout_page_found', 'plakatdyr_wfacp_kundete_register', 1, 2 ); | |
| add_action( 'wfacp_after_checkout_page_found', 'plakatdyr_wfacp_kundete_register', 1, 1 ); | |
| function plakatdyr_wfacp_kundete_register() { | |
| static $done = false; | |
| if ( $done ) { | |
| return; | |
| } | |
| $done = true; | |
| add_action( 'wp_enqueue_scripts', 'plakatdyr_wfacp_kundete_assets', 30 ); | |
| add_action( 'woocommerce_checkout_before_customer_details', 'plakatdyr_wfacp_kundete_echo', 5 ); | |
| add_filter( 'woocommerce_checkout_get_value', 'plakatdyr_wfacp_kundete_default', 100000, 2 ); | |
| } | |
| function plakatdyr_wfacp_kundete_assets() { | |
| $v = '1.7.0'; | |
| if ( ! wp_style_is( 'plakatdr', 'enqueued' ) && ! wp_style_is( 'plakatdr', 'to_print' ) ) { | |
| $base = get_template_directory(); | |
| $path = is_readable( $base . '/dist/main.min.css' ) ? '/dist/main.min.css' : '/style.css'; | |
| if ( is_readable( $base . $path ) ) { | |
| $u = (string) filemtime( $base . $path ); | |
| if ( ! wp_style_is( 'plakatdr', 'registered' ) ) { | |
| wp_register_style( 'plakatdr', get_template_directory_uri() . $path, [], $u ); | |
| } | |
| wp_enqueue_style( 'plakatdr' ); | |
| } | |
| } | |
| $deps = ( wp_style_is( 'plakatdr', 'registered' ) || wp_style_is( 'plakatdr', 'enqueued' ) ) ? [ 'plakatdr' ] : []; | |
| wp_register_style( 'plakatdr-wfacp-kundete', false, $deps, $v ); | |
| wp_enqueue_style( 'plakatdr-wfacp-kundete' ); | |
| $css = <<<'CSS' | |
| #wfacp-sec-wrapper #wfacp_checkout_form #plakatdr-kundete,#wfacp-e-form #wfacp_checkout_form #plakatdr-kundete{clear:both;width:100%;max-width:100%;margin:0 0 20px;box-sizing:border-box} | |
| #wfacp-sec-wrapper #wfacp_checkout_form #plakatdr-kundete input[type=radio],#wfacp-e-form #wfacp_checkout_form #plakatdr-kundete input[type=radio]{position:absolute!important;opacity:0!important;width:1px!important;height:1px!important;margin:-1px!important;padding:0!important;border:0!important;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none!important} | |
| #wfacp-sec-wrapper #plakatdr-kundete .columns.is-mobile,#wfacp-e-form #plakatdr-kundete .columns.is-mobile{display:flex!important;flex-wrap:nowrap!important;gap:12px;margin:0!important;width:100%} | |
| #wfacp-sec-wrapper #plakatdr-kundete .column,#wfacp-e-form #plakatdr-kundete .column{flex:1 1 0!important;max-width:none!important;width:auto!important;padding:0!important;margin:0} | |
| #wfacp-sec-wrapper #plakatdr-kundete .field,#wfacp-e-form #plakatdr-kundete .field{width:100%;margin:0;display:block} | |
| #wfacp-sec-wrapper #plakatdr-kundete .is-radio,#wfacp-e-form #plakatdr-kundete .is-radio{position:relative;display:flex;align-items:center;justify-content:center;width:100%;min-height:52px;padding:12px 16px;border:1px solid #e5e5e8;border-radius:10px;background:#f2f2f4;color:#3a3a3a;font-weight:600;font-size:16px;line-height:1.2;text-align:center;white-space:nowrap;cursor:pointer;box-sizing:border-box;transition:background .15s ease,color .15s ease,border-color .15s ease} | |
| #wfacp-sec-wrapper #plakatdr-kundete .is-radio:hover,#wfacp-e-form #plakatdr-kundete .is-radio:hover{background:#e8e8ec} | |
| #wfacp-sec-wrapper #plakatdr-kundete .is-radio.is-selected,#wfacp-e-form #plakatdr-kundete .is-radio.is-selected,#wfacp-sec-wrapper #plakatdr-kundete .is-radio:has(input[type=radio]:checked),#wfacp-e-form #plakatdr-kundete .is-radio:has(input[type=radio]:checked){background:#3a5da3;border-color:#3a5da3;color:#fff} | |
| #plakatdr-kundete-fields{display:flex;flex-wrap:wrap;gap:16px;width:100%;margin:12px 0 0;box-sizing:border-box} | |
| #plakatdr-kundete-fields > .form-row{width:calc(50% - 8px);max-width:calc(50% - 8px);flex:0 0 calc(50% - 8px);margin:0;padding:0;box-sizing:border-box;float:none;clear:none} | |
| @media (max-width:600px){#plakatdr-kundete-fields > .form-row{width:100%;max-width:100%;flex-basis:100%}} | |
| CSS; | |
| wp_add_inline_style( 'plakatdr-wfacp-kundete', $css ); | |
| } | |
| /** | |
| * Remove the EAN Bruger ID field. The theme registers it (inc/woocommerce/checkout.php) | |
| * and WFACP re-merges its saved page-layout copy at priority 10, so it must be unset | |
| * later than that — removing it from the fields array keeps it out of both rendering | |
| * and checkout validation. | |
| */ | |
| add_filter( 'woocommerce_checkout_fields', function ( $fields ) { | |
| unset( $fields['billing']['billing_company_ean_user_id'] ); | |
| return $fields; | |
| }, 100000 ); | |
| function plakatdyr_wfacp_kundete_default( $value, $key ) { | |
| if ( 'customer-type' === $key && ( null === $value || false === $value || '' === $value ) ) { | |
| return 'private'; | |
| } | |
| return $value; | |
| } | |
| function plakatdyr_wfacp_kundete_echo() { | |
| $checkout = function_exists( 'WC' ) ? WC()->checkout() : null; | |
| if ( ! $checkout ) { | |
| return; | |
| } | |
| $ct = (string) $checkout->get_value( 'customer-type' ); | |
| if ( '' === $ct ) { | |
| $ct = 'private'; | |
| } | |
| ?> | |
| <div id="plakatdr-kundete" class="company-toggle has-text-centered"> | |
| <div class="columns is-mobile is-centered"> | |
| <div class="column is-narrow"> | |
| <div class="field is-inline-flex justify-end"> | |
| <label class="is-radio"> | |
| <input name="customer-type" type="radio" value="private" <?php checked( $ct, 'private' ); ?> /> | |
| <?php echo esc_html( 'PRIVAT' ); ?> | |
| </label> | |
| </div> | |
| </div> | |
| <div class="column is-narrow"> | |
| <div class="field is-inline-flex"> | |
| <label class="is-radio"> | |
| <input name="customer-type" type="radio" value="company" <?php checked( $ct, 'company' ); ?> /> | |
| <?php echo esc_html( 'ERHVERV' ); ?> | |
| </label> | |
| </div> | |
| </div> | |
| <div class="column is-narrow"> | |
| <div class="field is-inline-flex"> | |
| <label class="is-radio"> | |
| <input name="customer-type" type="radio" value="institution" <?php checked( $ct, 'institution' ); ?> /> | |
| <?php echo esc_html( 'INSTITUTION' ); ?> | |
| </label> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| (function(){ | |
| var IDS = ['billing_company_field','billing_company_vat_field','billing_company_ean_field']; | |
| function currentType(){ | |
| try{ var s = sessionStorage.getItem('customerType'); if(s){ return s; } }catch(e){} | |
| var c = document.querySelector('input[name="customer-type"]:checked'); | |
| return c ? c.value : 'private'; | |
| } | |
| function syncType(){ | |
| // The theme (CheckoutCustomerTypeSelector) shows/hides the company fields from | |
| // sessionStorage('customerType'), not the radio. Align the radio with that stored value so the | |
| // selected box always matches the fields the theme reveals — otherwise the toggle can say PRIVAT | |
| // while the institution fields are shown. | |
| var r = document.querySelector('input[name="customer-type"][value="' + currentType() + '"]'); | |
| if(r && !r.checked){ r.checked = true; } | |
| } | |
| function move(){ | |
| var toggle = document.getElementById('plakatdr-kundete'); | |
| if(!toggle) return; | |
| var wrap = document.getElementById('plakatdr-kundete-fields'); | |
| if(!wrap){ | |
| wrap = document.createElement('div'); | |
| wrap.id = 'plakatdr-kundete-fields'; | |
| } | |
| if(wrap.previousElementSibling !== toggle){ | |
| toggle.parentNode.insertBefore(wrap, toggle.nextSibling); | |
| } | |
| IDS.forEach(function(id){ | |
| var el = document.getElementById(id); | |
| if(el && el.parentNode !== wrap){ | |
| wrap.appendChild(el); | |
| } | |
| }); | |
| if(!wrap.children.length && wrap.parentNode){ | |
| wrap.parentNode.removeChild(wrap); | |
| } | |
| } | |
| function selstate(){ | |
| var box = document.getElementById('plakatdr-kundete'); | |
| if(!box) return; | |
| box.querySelectorAll('label.is-radio').forEach(function(l){ | |
| var r = l.querySelector('input[type=radio]'); | |
| l.classList.toggle('is-selected', !!(r && r.checked)); | |
| }); | |
| } | |
| document.addEventListener('change', function(e){ | |
| if(e.target && e.target.name === 'customer-type'){ selstate(); } | |
| }); | |
| function init(){ syncType(); move(); selstate(); } | |
| if(window.jQuery){ | |
| jQuery(function(){ init(); }); | |
| jQuery(document.body).on('updated_checkout', init); | |
| } else { | |
| document.addEventListener('DOMContentLoaded', init); | |
| } | |
| })(); | |
| </script> | |
| <?php | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment