クラス
CouponForm
ソース ソース
ファイル: src/Components/CouponForm/CouponForm.php
class CouponForm extends VueComponent
{
/**
* Loads CSS
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
*/
public function init() {
add_action('wp_enqueue_scripts', function () {
(new Semantic())->loadButtonCss();
});
}
/**
* Returns component name as is recognized by Vue.
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return string
*/
public function getComponentName() {
return 'couponFormComponent';
}
/**
* Coupon form Vue template.
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @global array $usces_entries
* @return void
*/
public function template() {
global $usces_entries;
$propsAndEvents = [];
if ($this->controlledComponent === true) {
$propsAndEvents[] = 'v-bind:loading-prop="loading"';
$propsAndEvents[] = 'v-bind:purchase-payload="purchasePayload"';
$propsAndEvents[] = '@update-payload="updatePayload"';
$propsAndEvents[] = '@update-order="updateOrder"';
$propsAndEvents[] = '@update-loading="updateLoading"';
}
$allPropsAndEvents = join(' ', $propsAndEvents);
$class = (
usces_is_member_system() &&
usces_is_member_system_point() &&
usces_is_login()
) ? ' class="cp_fr"' : '';
/**
* Filters the coupon form apply button's CSS class on the Quickpay page
*
* @important
* @param string $cssclass
*/
$btnclass = apply_filters(
'wcexaap_filter_checkout_review_coupon_form_button_class',
'ui ' . AmazonPay::getThemeConfig()['btnprimary'] . ' basic button'
);
/**
* Filters the coupon form reset button's CSS class on the Quickpay page
*
* @important
* @param string $cssclass
*/
$resetbtnclass = apply_filters(
'wcexaap_filter_checkout_review_coupon_form_reset_button_class',
'ui button'
);
$usedcoupon = isset($usces_entries['order']['usedcoupon']) ? $usces_entries['order']['usedcoupon'] : '';
?>
<coupon-form-component
usedcoupon-session-val='<?php echo esc_html($usedcoupon); ?>'
<?php echo $allPropsAndEvents; ?>
inline-template
>
<div>
<?php ob_start(); ?>
<?php
/**
* Mirrored WCEX Coupon filter
*
* @ignore
*/
echo apply_filters('wccp_filter_coupon_inform', '', $usces_entries);
?>
<div v-cloak v-if="errorMessage" class="error_message" v-html="errorMessage"></div>
<?php ob_start(); ?>
<table cellspacing="0" id="coupon_table" <?php echo esc_attr($class);?>>
<tr>
<td><?php echo esc_html__('Coupon Code', 'coupon'); ?></td>
<td>
<input
name="offer[usedcoupon]"
class="used_coupon"
type="text"
v-model="usedcoupon"
/>
</td>
</tr>
<tr>
<td colspan="2">
<?php ob_start(); ?>
<button
v-on:click.stop.prevent="useCoupon"
class="<?php echo esc_attr($btnclass); ?>"
v-bind:class="{ disabled: loading }"
>
<?php echo esc_html__('Use a coupon', 'coupon'); ?>
</button>
<button
v-on:click.stop.prevent="resetCoupon"
class="<?php echo esc_attr($resetbtnclass); ?>"
v-bind:class="{ disabled: loading }"
>
<?php echo esc_html__('Cancel', 'coupon'); ?>
</button>
<?php $buttonshtml = ob_get_clean(); ?>
<?php
/**
* Filters the coupon form buttons HTML on the Quickpay page
*
* @param string $buttonshtml
* @param string $btnclass See {@see 'wcexaap_filter_checkout_review_coupon_form_button_class'}
* @param string $resetbtnclass See {@see 'wcexaap_filter_checkout_review_coupon_form_reset_button_class'}
*/
echo apply_filters(
'wcexaap_filter_couponform_buttons_html',
$buttonshtml,
$btnclass,
$resetbtnclass
);
?>
</td>
</tr>
</table>
<?php $tablehtml = ob_get_clean(); ?>
<?php
/**
* Filters the coupon form table HTML on the Quickpay page
*
* @param string $tablehtml
* @param string $class
* @param string $btnclass See {@see 'wcexaap_filter_checkout_review_coupon_form_button_class'}
* @param string $resetbtnclass See {@see 'wcexaap_filter_checkout_review_coupon_form_reset_button_class'}
*/
echo apply_filters(
'wcexaap_filter_couponform_table_html',
$tablehtml,
$class,
$btnclass,
$resetbtnclass
);
?>
<?php $vuehtml = ob_get_clean(); ?>
<?php
/**
* Filters the `coupon-form-component` Vue HTML on the Quickpay page
*
* @param string $vuehtml
* @param string $class
* @param string $btnclass See {@see 'wcexaap_filter_checkout_review_coupon_form_button_class'}
* @param string $resetbtnclass See {@see 'wcexaap_filter_checkout_review_coupon_form_reset_button_class'}
*/
echo apply_filters(
'wcexaap_filter_couponform_component',
$vuehtml,
$class,
$btnclass,
$resetbtnclass
);
?>
</div>
</coupon-form-component>
<?php
}
}
- getComponentName — Returns component name as is recognized by Vue.
- init — Loads CSS
- template — Coupon form Vue template.