Skip to content

Commit

Permalink
Merge pull request #939 from mollie/fix/populate-birth-on-pay-page-PI…
Browse files Browse the repository at this point in the history
…WOO-521

Add birth from meta to fields in pay page PIWOO-521
  • Loading branch information
mmaymo authored Sep 25, 2024
2 parents b924328 + 6cc2ad0 commit 15236a0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
27 changes: 5 additions & 22 deletions src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class In3FieldsStrategy implements PaymentFieldsStrategyI
{
use PaymentFieldsStrategiesTrait;

const FIELD_BIRTHDATE = "billing_birthdate";
const FIELD_PHONE = "billing_phone_in3";

Expand All @@ -15,12 +17,14 @@ public function execute($gateway, $dataHelper)
$showPhoneField = false;
$isPhoneRequired = get_option('mollie_wc_is_phone_required_flag');
$phoneValue = false;
$birthValue = false;

if (is_checkout_pay_page()) {
$showBirthdateField = true;
$showPhoneField = true;
$order = $this->getOrderIdOnPayForOrderPage();
$phoneValue = $order->get_billing_phone();
$birthValue = $order->get_meta('billing_birthdate');
}

if (is_checkout() && !is_checkout_pay_page() && !$isPhoneRequired) {
Expand All @@ -35,31 +39,10 @@ public function execute($gateway, $dataHelper)
}

if ($showBirthdateField) {
$this->dateOfBirth();
$this->dateOfBirth($birthValue);
}
}

protected function getOrderIdOnPayForOrderPage()
{
global $wp;
$orderId = absint($wp->query_vars['order-pay']);
return wc_get_order($orderId);
}

protected function dateOfBirth()
{
?>
<p class="form-row form-row-wide" id="billing_birthdate_field">
<label for="<?php echo esc_attr(self::FIELD_BIRTHDATE); ?>" class=""><?php echo esc_html__('Birthdate', 'mollie-payments-for-woocommerce'); ?>
</label>
<span class="woocommerce-input-wrapper">
<input type="date" class="input-text " name="<?php echo esc_attr(self::FIELD_BIRTHDATE); ?>"
id="<?php echo esc_attr(self::FIELD_BIRTHDATE); ?>" value=""
autocomplete="birthdate"></span>
</p>
<?php
}

protected function phoneNumber($phoneValue)
{
$phoneValue = $phoneValue ?: '';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Mollie\WooCommerce\PaymentMethods\PaymentFieldsStrategies;

trait PaymentFieldsStrategiesTrait
{
protected function getOrderIdOnPayForOrderPage()
{
global $wp;
$orderId = absint($wp->query_vars['order-pay']);
return wc_get_order($orderId);
}

protected function dateOfBirth($birthValue)
{
$birthValue = $birthValue ?: '';
?>
<p class="form-row form-row-wide" id="billing_birthdate_field">
<label for="<?php echo esc_attr(self::FIELD_BIRTHDATE); ?>" class=""><?php echo esc_html__('Birthdate', 'mollie-payments-for-woocommerce'); ?>
</label>
<span class="woocommerce-input-wrapper">
<input type="date" class="input-text " name="<?php echo esc_attr(self::FIELD_BIRTHDATE); ?>"
id="<?php echo esc_attr(self::FIELD_BIRTHDATE); ?>" value="<?php echo esc_attr($birthValue); ?>"
autocomplete="birthdate"></span>
</p>
<?php
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class RivertyFieldsStrategy implements PaymentFieldsStrategyI
{
use PaymentFieldsStrategiesTrait;

const FIELD_BIRTHDATE = "billing_birthdate";
const FIELD_PHONE = "billing_phone_riverty";

Expand All @@ -15,12 +17,14 @@ public function execute($gateway, $dataHelper)
$showPhoneField = false;
$isPhoneRequired = get_option('mollie_wc_is_phone_required_flag');
$phoneValue = false;
$birthValue = false;

if (is_checkout_pay_page()) {
$showBirthdateField = true;
$showPhoneField = true;
$order = $this->getOrderIdOnPayForOrderPage();
$phoneValue = $order->get_billing_phone();
$birthValue = $order->get_meta('billing_birthdate');
}

if (is_checkout() && !is_checkout_pay_page() && !$isPhoneRequired) {
Expand All @@ -35,31 +39,10 @@ public function execute($gateway, $dataHelper)
}

if ($showBirthdateField) {
$this->dateOfBirth();
$this->dateOfBirth($birthValue);
}
}

protected function getOrderIdOnPayForOrderPage()
{
global $wp;
$orderId = absint($wp->query_vars['order-pay']);
return wc_get_order($orderId);
}

protected function dateOfBirth()
{
?>
<p class="form-row form-row-wide" id="billing_birthdate_field">
<label for="<?php echo esc_attr(self::FIELD_BIRTHDATE); ?>" class=""><?php echo esc_html__('Birthdate', 'mollie-payments-for-woocommerce'); ?>
</label>
<span class="woocommerce-input-wrapper">
<input type="date" class="input-text " name="<?php echo esc_attr(self::FIELD_BIRTHDATE); ?>"
id="<?php echo esc_attr(self::FIELD_BIRTHDATE); ?>" value=""
autocomplete="birthdate"></span>
</p>
<?php
}

protected function phoneNumber($phoneValue)
{
$phoneValue = $phoneValue ?: '';
Expand Down

0 comments on commit 15236a0

Please sign in to comment.