Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 164 additions & 1 deletion inc/admin-pages/class-checkout-form-edit-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,174 @@ public function render_steps(): void {
wu_get_template(
'base/checkout-forms/steps',
[
'checkout_form' => $this->get_object()->get_slug(),
'checkout_form' => $this->get_object()->get_slug(),
'price_variation_notice_products' => $this->get_price_variation_notice_products(),
'template_selection_notice_products' => $this->get_template_selection_notice_products(),
]
);
}

/**
* Returns the names of products that do NOT force a specific site template
* when the checkout form has no template selection field.
*
* Used to render an admin notice in the editor warning that the template
* selection field is required for customers to pick a site template.
*
* @since 2.4.13
* @return array
*/
protected function get_template_selection_notice_products(): array {

$form = $this->get_object();

if ( ! is_a($form, \WP_Ultimo\Models\Checkout_Form::class)) {
return [];
}

$template_selection_fields = $form->get_all_fields_by_type('template_selection');

if ( ! empty($template_selection_fields)) {
return [];
}

$product_id_fields = $form->get_all_fields_by_type(['pricing_table', 'products']);

if (empty($product_id_fields)) {
return [];
}

$product_ids = [];

foreach ($product_id_fields as $field) {
$ids_string = '';

if ('pricing_table' === ($field['type'] ?? '')) {
$ids_string = (string) ($field['pricing_table_products'] ?? '');
} elseif ('products' === ($field['type'] ?? '')) {
$ids_string = (string) ($field['products'] ?? '');
}

if ('' === $ids_string) {
continue;
}

foreach (explode(',', $ids_string) as $id) {
$id = absint(trim($id));

if ($id) {
$product_ids[ $id ] = $id;
}
}
}

if (empty($product_ids)) {
return [];
}

$names = [];

foreach ($product_ids as $product_id) {
$product = wu_get_product($product_id);

if ( ! $product) {
continue;
}

$limitations = $product->get_limitations();

if ( ! $limitations || ! isset($limitations->site_templates)) {
$names[] = $product->get_name();
continue;
}

$mode = $limitations->site_templates->get_mode();

if (\WP_Ultimo\Limitations\Limit_Site_Templates::MODE_ASSIGN_TEMPLATE !== $mode) {
$names[] = $product->get_name();
}
}

return $names;
}

/**
* Returns the names of products with price variations that lack a period
* selection field on this checkout form.
*
* Used to render an admin notice in the editor warning that the period
* selection field is required for price variations to be selectable.
*
* @since 2.4.13
* @return array
*/
protected function get_price_variation_notice_products(): array {

$form = $this->get_object();

if ( ! is_a($form, \WP_Ultimo\Models\Checkout_Form::class)) {
return [];
}

$period_selection_fields = $form->get_all_fields_by_type('period_selection');

if ( ! empty($period_selection_fields)) {
return [];
}

$product_id_fields = $form->get_all_fields_by_type(['pricing_table', 'products']);

if (empty($product_id_fields)) {
return [];
}

$product_ids = [];

foreach ($product_id_fields as $field) {
$ids_string = '';

if ('pricing_table' === ($field['type'] ?? '')) {
$ids_string = (string) ($field['pricing_table_products'] ?? '');
} elseif ('products' === ($field['type'] ?? '')) {
$ids_string = (string) ($field['products'] ?? '');
}

if ('' === $ids_string) {
continue;
}

foreach (explode(',', $ids_string) as $id) {
$id = absint(trim($id));

if ($id) {
$product_ids[ $id ] = $id;
}
}
}

if (empty($product_ids)) {
return [];
}

$names = [];

foreach ($product_ids as $product_id) {
$product = wu_get_product($product_id);

if ( ! $product) {
continue;
}

$variations = $product->get_price_variations();

if ( ! empty($variations)) {
$names[] = $product->get_name();
}
}

return $names;
}

/**
* Renders the Vue JS Templates.
*
Expand Down
40 changes: 40 additions & 0 deletions views/base/checkout-forms/steps.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,46 @@
?>
<div id="wu-checkout-editor-app">

<?php if ( ! empty($price_variation_notice_products)) : ?>
<div class="wu-py-3 wu-px-4 wu-mb-4 wu-bg-yellow-100 wu-text-yellow-800 wu-border wu-border-solid wu-border-yellow-400 wu-rounded">
<strong><?php esc_html_e('Period Selection field missing', 'ultimate-multisite'); ?></strong>
<p class="wu-my-1">
<?php
echo esc_html(
sprintf(
/* translators: %s: comma-separated list of product names */
__('The following products have price variations, but this checkout form has no Period Selection field. Customers will not be able to choose between the variation prices: %s.', 'ultimate-multisite'),
implode(', ', $price_variation_notice_products)
)
);
?>
</p>
<p class="wu-my-1">
<?php esc_html_e('Add a Period Selection field to one of the steps to allow customers to switch between the available billing periods.', 'ultimate-multisite'); ?>
</p>
</div>
<?php endif; ?>

<?php if ( ! empty($template_selection_notice_products)) : ?>
<div class="wu-py-3 wu-px-4 wu-mb-4 wu-bg-yellow-100 wu-text-yellow-800 wu-border wu-border-solid wu-border-yellow-400 wu-rounded">
<strong><?php esc_html_e('Template Selection field missing', 'ultimate-multisite'); ?></strong>
<p class="wu-my-1">
<?php
echo esc_html(
sprintf(
/* translators: %s: comma-separated list of product names */
__('The following products do not force a specific site template, but this checkout form has no Template Selection field. Customers will not be able to choose a site template: %s.', 'ultimate-multisite'),
implode(', ', $template_selection_notice_products)
)
);
?>
</p>
<p class="wu-my-1">
<?php esc_html_e('Add a Template Selection field to one of the steps, or set these products to assign a specific template via their site template limitations.', 'ultimate-multisite'); ?>
</p>
</div>
<?php endif; ?>

<!-- Add new Step Section -->
<div id="wp-ultimo-list-table-add-new-1" class="postbox wu-mb-0" v-cloak>

Expand Down
Loading