implode(',', array_keys(wu_get_plans_as_options())), 'pricing_table_template' => 'list', 'force_different_durations' => false, 'hide_pricing_table_when_pre_selected' => false, ]; } /** * List of keys of the default fields we want to display on the builder. * * @since 2.0.0 * @return array */ public function default_fields() { return [ // 'name', ]; } /** * If you want to force a particular attribute to a value, declare it here. * * @since 2.0.0 * @return array */ public function force_attributes() { return [ 'id' => 'pricing_table', 'name' => __('Plan Selection', 'wp-ultimo'), 'required' => true, ]; } /** * Returns the list of available pricing table templates. * * @since 2.0.0 * @return array */ public function get_pricing_table_templates() { $available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('pricing_table'); return $available_templates; } /** * Returns the list of additional fields specific to this type. * * @since 2.0.0 * @return array */ public function get_fields() { $editor_fields = []; $editor_fields['pricing_table_products'] = [ 'type' => 'model', 'title' => __('Products', 'wp-ultimo'), 'placeholder' => __('e.g. Premium', 'wp-ultimo'), 'desc' => __('Be sure to add the products in the order you want them to show up.', 'wp-ultimo'), 'tooltip' => '', 'order' => 20, 'html_attr' => [ 'data-model' => 'product', 'data-value-field' => 'id', 'data-label-field' => 'name', 'data-search-field' => 'name', 'data-include' => implode(',', array_keys(wu_get_plans_as_options())), 'data-max-items' => 999, ], ]; $editor_fields['force_different_durations'] = [ 'type' => 'toggle', 'title' => __('Force Different Durations', 'wp-ultimo'), 'desc' => __('Check this option to force the display of plans with different recurring durations.', 'wp-ultimo'), 'tooltip' => '', 'value' => 0, 'order' => 22, 'html_attr' => [ 'v-model' => 'force_different_durations', ], ]; $editor_fields['hide_pricing_table_when_pre_selected'] = [ 'type' => 'toggle', 'title' => __('Hide when Pre-Selected', 'wp-ultimo'), 'desc' => __('Prevent customers from seeing this field when a plan was already selected via the URL.', 'wp-ultimo'), 'tooltip' => __('If the pricing table field is the only field in the current step, the step will be skipped.', 'wp-ultimo'), 'value' => 0, 'order' => 24, 'html_attr' => [ 'v-model' => 'hide_pricing_table_when_pre_selected', ], ]; $editor_fields['pricing_table_template'] = [ 'type' => 'group', 'desc' => Field_Templates_Manager::get_instance()->render_preview_block('pricing_table'), 'order' => 26, 'fields' => [ 'pricing_table_template' => [ 'type' => 'select', 'title' => __('Pricing Table Template', 'wp-ultimo'), 'placeholder' => __('Select your Template', 'wp-ultimo'), 'options' => [$this, 'get_pricing_table_templates'], 'wrapper_classes' => 'wu-flex-grow', 'html_attr' => [ 'v-model' => 'pricing_table_template', ], ], ], ]; // @todo: re-add developer notes. // $editor_fields['_dev_note_develop_your_own_template_2'] = array( // 'type' => 'note', // 'order' => 99, // 'wrapper_classes' => 'sm:wu-p-0 sm:wu-block', // 'classes' => '', // 'desc' => sprintf('
%s
', __('Want to add customized pricing table templates?
See how you can do that here.', 'wp-ultimo')), // ); return $editor_fields; } /** * Returns the field/element actual field array to be used on the checkout form. * * @since 2.0.0 * * @param array $attributes Attributes saved on the editor form. * @return array An array of fields, not the field itself. */ public function to_fields_array($attributes) { if (wu_get_isset($attributes, 'pricing_table_template') === 'legacy') { wp_enqueue_style('legacy-shortcodes', wu_get_asset('legacy-shortcodes.css', 'css'), ['dashicons'], wu_get_version()); wp_add_inline_style('legacy-shortcodes', \WP_Ultimo\Checkout\Legacy_Checkout::get_instance()->get_legacy_dynamic_styles()); } $product_list = explode(',', (string) $attributes['pricing_table_products']); $products = array_map('wu_get_product', $product_list); /** * Clear the product list out of invalid items and inactive products. */ $products = array_filter($products, fn($item) => $item && $item->is_active()); /** * Hide when pre-selected. */ if (wu_should_hide_form_field($attributes)) { return []; } $template_attributes = [ 'products' => $products, 'name' => $attributes['name'], 'force_different_durations' => $attributes['force_different_durations'], 'classes' => wu_get_isset($attributes, 'element_classes', ''), ]; $template_class = Field_Templates_Manager::get_instance()->get_template_class('pricing_table', $attributes['pricing_table_template']); $content = $template_class ? $template_class->render_container($template_attributes) : __('Template does not exist.', 'wp-ultimo'); $checkout_fields = []; $checkout_fields[ $attributes['id'] ] = [ 'type' => 'note', 'id' => $attributes['id'], 'wrapper_classes' => wu_get_isset($attributes, 'wrapper_element_classes', ''), 'classes' => wu_get_isset($attributes, 'element_classes', ''), 'desc' => $content, 'wrapper_html_attr' => [ 'style' => $this->calculate_style_attr(), ], ]; return $checkout_fields; } }