PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / admin / classes / admin-options / fields / select-ajax / template.php

template.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.2, at admin/classes/admin-options/fields/select-ajax/template.php

75 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Template: Select Ajax field.
4 *
5 * @var array<string, mixed> $settings Field configuration.
6 * @var mixed $value Current saved value.
7 * @var string $module_id Module ID.
8 *
9 * @package Merchant
10 * @since 2.2.5
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 $settings = wp_parse_args( $settings, array(
18 'source' => 'post',
19 ) );$ids = ( is_array( $value ) && ! empty( $value ) ) ? $value : (array) $value;
20
21 if ( isset( $settings['multiple'] ) ) {
22 $multiple = $settings['multiple'] === true ? 'multiple' : '';
23 } else {
24 $multiple = 'multiple';
25 }
26
27 $placeholder = $settings['placeholder'] ?? '';
28 ?>
29 <select
30 name="merchant[<?php echo esc_attr( $settings['id'] ); ?>]<?php echo esc_attr( $multiple ? '[]' : '' ); ?>"
31 <?php echo esc_attr( $multiple ); ?>
32 data-source="<?php echo esc_attr( $settings['source'] ); ?>"
33 data-placeholder="<?php echo esc_attr( $placeholder ); ?>">
34 <?php
35 if ( ! empty( $ids ) ) {
36 foreach ( $ids as $item_id ) {
37 switch ( $settings['source'] ) {
38 case 'post':
39 case 'product':
40 $post_obj = get_post( $item_id );
41 if ( ! empty( $post_obj ) ) {
42 echo '<option value="' . esc_attr( (string) $post_obj->ID ) . '" selected>' . esc_html( $post_obj->post_title ) . '</option>';
43 }
44 break;
45 case 'user':
46 $user = get_user_by( 'ID', $item_id );
47 if ( $user ) {
48 echo '<option value="' . esc_attr( (string) $user->ID ) . '" selected>' . esc_html( $user->display_name ) . '</option>';
49 }
50 break;
51 case 'options':
52 break;
53 }
54 }
55 }
56 if ( $settings['source'] === 'options' ) {
57 $value = ! empty( $value ) ? $value : '';
58
59 foreach ( $settings['options'] as $option ) {
60 if ( isset( $option['options'] ) ) {
61 echo '<optgroup label="' . esc_attr( $option['text'] ) . '">';
62 foreach ( $option['options'] as $child_option ) {
63 $selected_value = is_array( $value ) ? in_array( $child_option['id'], $value, true ) : $child_option['id'];
64 echo '<option value="' . esc_attr( $child_option['id'] ) . '" ' . selected( $selected_value, is_array( $value ) ? true : $value, false ) . '>' . esc_html( $child_option['text'] ) . '</option>';
65 }
66 echo '</optgroup>';
67 } else {
68 $selected_value = is_array( $value ) ? in_array( $option['id'], $value, true ) : $option['id'];
69 echo '<option value="' . esc_attr( $option['id'] ) . '" ' . selected( $selected_value, is_array( $value ) ? true : $value, false ) . '>' . esc_html( $option['text'] ) . '</option>';
70 }
71 }
72 } ?>
73 </select>
74 <?php
75