-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
796 additions
and
604 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
70 changes: 61 additions & 9 deletions
70
assets/scripts/frontend/controllers/address-page.controller.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,77 @@ | ||
const $ = jQuery; | ||
|
||
export default class AddressPageController { | ||
private $inputs: JQuery<HTMLInputElement>; | ||
private selector = '.entity-type-control input'; | ||
private locale: Record<string, string>; | ||
|
||
public init(): void { | ||
this.$inputs = $('.entity-type-control input[type="radio"]'); | ||
this.locale = JSON.parse(window.wc_address_i18n_params.locale_fields); | ||
} | ||
|
||
public finalize(): void { | ||
this.$inputs.on('click', ({ currentTarget }) => | ||
this.toggleFields($(currentTarget)), | ||
$(document.body).on('change refresh', this.selector, (e) => { | ||
console.log('change refresh'); | ||
this.toggleEntityType($(e.target)); | ||
}); | ||
|
||
$(document.body).on('country_to_state_changing', () => { | ||
window.setTimeout( | ||
() => this.toggleEntityType($(`${this.selector}:checked`)), | ||
100, | ||
); | ||
console.log('country_to_state_changing'); | ||
}); | ||
} | ||
|
||
private toggleEntityType($input: JQuery<HTMLInputElement>): void { | ||
const isCompany = $input.val() === 'company'; | ||
|
||
console.log($input.is(':checked'), $input.val()); | ||
|
||
this.isRequired($<HTMLParagraphElement>('.entity-type-toggle'), isCompany); | ||
} | ||
|
||
private isRequired( | ||
$field: JQuery<HTMLParagraphElement>, | ||
required: boolean, | ||
): void { | ||
$field.find('input').prop({ | ||
'aria-required': required, | ||
disabled: !required, | ||
}); | ||
|
||
if (required) { | ||
$field.find('label .optional').remove(); | ||
$field.addClass('shown validate-required'); | ||
|
||
if ($field.find('label .required').length === 0) { | ||
$field | ||
.find('label') | ||
.append( | ||
`<abbr class="required" title="${window.wc_address_i18n_params.i18n_required_text}">*</abbr>`, | ||
); | ||
} | ||
|
||
return; | ||
} | ||
|
||
$field.find('label .required').remove(); | ||
$field.removeClass( | ||
'shown validate-required woocommerce-invalid woocommerce-invalid-required-field', | ||
); | ||
this.toggleFields(this.$inputs.filter(':checked')); | ||
|
||
if ($field.find('label .optional').length === 0) { | ||
$field | ||
.find('label') | ||
.append( | ||
`<abbr class="optional" title="${window.wc_address_i18n_params.i18n_optional_text}">${window.wc_address_i18n_params.i18n_optional_text}</abbr>`, | ||
); | ||
} | ||
} | ||
|
||
private toggleFields($toggle: JQuery<HTMLInputElement>): void { | ||
const isPerson = $toggle.attr('value') === 'person'; | ||
|
||
$('.hide-if-person').toggleClass('shown', !isPerson).find('input').prop({ | ||
required: !isPerson, | ||
disabled: isPerson, | ||
}); | ||
$('.hide-if-person').toggleClass('shown', !isPerson); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Edit_User_Controller class file. | ||
* | ||
* @package Serbian Addons for WooCommerce | ||
*/ | ||
|
||
namespace Oblak\WCSRB\Admin; | ||
|
||
use Oblak\WP\Abstracts\Hook_Caller; | ||
use Oblak\WP\Decorators\Filter; | ||
use Oblak\WP\Decorators\Hookable; | ||
|
||
/** | ||
* Changes the fields on the checkout page | ||
* | ||
* @since 3.8.0 | ||
*/ | ||
#[Hookable( 'admin_init', 99 )] | ||
class Edit_User_Controller extends Hook_Caller { | ||
/** | ||
* Adds the company information to the customer meta fields. | ||
* | ||
* @param array $fields Customer meta fields. | ||
* @return array Modified customer meta fields | ||
*/ | ||
#[Filter( 'woocommerce_customer_meta_fields' )] | ||
public function modify_customer_meta_fields( array $fields ): array { | ||
$company = \array_search( 'billing_company', \array_keys( $fields['billing']['fields'] ), true ); | ||
|
||
//phpcs:disable SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder | ||
$fields['billing']['fields'] = \array_merge( | ||
\array_slice( $fields['billing']['fields'], 0, $company ), | ||
array( | ||
'billing_type' => array( | ||
'description' => '', | ||
'label' => \__( 'Customer type', 'serbian-addons-for-woocommerce' ), | ||
'options' => \wcsrb_get_entity_types(), | ||
'type' => 'select', | ||
), | ||
'billing_company' => $fields['billing']['fields']['billing_company'], | ||
'billing_mb' => array( | ||
'description' => '', | ||
'label' => \__( 'Company Number', 'serbian-addons-for-woocommerce' ), | ||
'type' => 'text', | ||
), | ||
'billing_pib' => array( | ||
'description' => '', | ||
'label' => \__( 'Tax Number', 'serbian-addons-for-woocommerce' ), | ||
'type' => 'text', | ||
), | ||
|
||
), | ||
\array_slice( $fields['billing']['fields'], $company ), | ||
); | ||
//phpcs:enable SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder | ||
|
||
return $fields; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.