/** * Add scenario config options. * * @param int $id * @param array $scenario_data * @param array $composite_data * @param int $product_id * @return void */ public function scenario_config($id, $scenario_data, $composite_data, $product_id) { ?> <div class="scenario_config_group"><?php foreach ($composite_data as $component_id => $component_data) { $modifier = ''; if (isset($scenario_data['modifier'][$component_id])) { $modifier = $scenario_data['modifier'][$component_id]; } else { $exclude = isset($scenario_data['exclude'][$component_id]) ? $scenario_data['exclude'][$component_id] : 'no'; if ($exclude === 'no') { $modifier = 'in'; } elseif ($exclude === 'masked') { $modifier = 'masked'; } else { $modifier = 'not-in'; } } ?> <div class="bto_scenario_selector"> <div class="form-field"> <label><?php echo apply_filters('woocommerce_composite_component_title', $component_data['title'], $component_id, $product_id); ?> </label> <div class="bto_scenario_modifier_wrapper bto_scenario_exclude_wrapper"> <select class="bto_scenario_modifier bto_scenario_exclude" name="bto_scenario_data[<?php echo $id; ?> ][modifier][<?php echo $component_id; ?> ]"> <option <?php selected($modifier, 'in', true); ?> value="in"><?php echo __('selection is'); ?> </option> <option <?php selected($modifier, 'not-in', true); ?> value="not-in"><?php echo __('selection is not'); ?> </option> <option <?php selected($modifier, 'masked', true); ?> value="masked"><?php echo __('selection is masked'); ?> </option> </select> </div> <div class="bto_scenario_selector_inner" <?php echo $modifier === 'masked' ? 'style="display:none"' : ''; ?> ><?php $component_options = WC_CP()->api->get_component_options($component_data); if (count($component_options) < 30) { $scenario_options = array(); $scenario_selections = array(); if ($component_data['optional'] === 'yes') { if (WC_CP_Scenarios::scenario_contains_product($scenario_data, $component_id, -1)) { $scenario_selections[] = -1; } $scenario_options[-1] = __('None', 'woocommerce-composite-products'); } if (WC_CP_Scenarios::scenario_contains_product($scenario_data, $component_id, 0)) { $scenario_selections[] = 0; } $scenario_options[0] = __('All Products and Variations', 'woocommerce-composite-products'); foreach ($component_options as $item_id) { $title = WC_CP_Helpers::get_product_title($item_id); if (!$title) { continue; } // Get product type $terms = get_the_terms($item_id, 'product_type'); $product_type = !empty($terms) && isset(current($terms)->name) ? sanitize_title(current($terms)->name) : 'simple'; if ($product_type === 'variable') { $product_title = $title . ' ' . __('— All Variations', 'woocommerce-composite-products'); $variation_descriptions = WC_CP_Helpers::get_product_variation_descriptions($item_id); } else { $product_title = $title; } if (WC_CP_Scenarios::scenario_contains_product($scenario_data, $component_id, $item_id)) { $scenario_selections[] = $item_id; } $scenario_options[$item_id] = $product_title; if ($product_type === 'variable') { if (!empty($variation_descriptions)) { foreach ($variation_descriptions as $variation_id => $description) { if (WC_CP_Scenarios::scenario_contains_product($scenario_data, $component_id, $variation_id)) { $scenario_selections[] = $variation_id; } $scenario_options[$variation_id] = $description; } } } } $optional_tip = $component_data['optional'] === 'yes' ? sprintf(__('<br/><strong>Pro Tip</strong>: Use the <strong>None</strong> option to control the <strong>Optional</strong> property of <strong>%s</strong> in this Scenario.', 'woocommerce-composite-products'), apply_filters('woocommerce_composite_component_title', $component_data['title'], $component_id, $product_id)) : ''; $select_tip = sprintf(__('Select products and variations from <strong>%1$s</strong>.<br/><strong>Tip</strong>: Choose the <strong>All Products and Variations</strong> option to add all products and variations available under <strong>%1$s</strong> in this Scenario.%2$s', 'woocommerce-composite-products'), apply_filters('woocommerce_composite_component_title', $component_data['title'], $component_id, $product_id), $optional_tip); ?> <select id="bto_scenario_ids_<?php echo $id; ?> _<?php echo $component_id; ?> " name="bto_scenario_data[<?php echo $id; ?> ][component_data][<?php echo $component_id; ?> ][]" style="width: 75%;" class="<?php echo WC_CP_Core_Compatibility::is_wc_version_gte_2_3() ? 'wc-enhanced-select' : 'chosen_select'; ?> bto_scenario_ids" multiple="multiple" data-placeholder="<?php echo __('Select products & variations…', 'woocommerce-composite-products'); ?> "><?php foreach ($scenario_options as $scenario_option_id => $scenario_option_description) { $option_selected = in_array($scenario_option_id, $scenario_selections) ? 'selected="selected"' : ''; echo '<option ' . $option_selected . 'value="' . $scenario_option_id . '">' . $scenario_option_description . '</option>'; } ?> </select> <span class="bto_scenario_select tips" data-tip="<?php echo $select_tip; ?> "></span><?php } else { $selections_in_scenario = array(); if (!empty($scenario_data['component_data'])) { foreach ($scenario_data['component_data'][$component_id] as $product_id_in_scenario) { if ($product_id_in_scenario == -1) { if ($component_data['optional'] === 'yes') { $selections_in_scenario[$product_id_in_scenario] = __('None', 'woocommerce-composite-products'); } } elseif ($product_id_in_scenario == 0) { $selections_in_scenario[$product_id_in_scenario] = __('All Products and Variations', 'woocommerce-composite-products'); } else { $product_in_scenario = wc_get_product($product_id_in_scenario); if (!$product_in_scenario) { continue; } if (!in_array($product_in_scenario->id, $component_options)) { continue; } if ($product_in_scenario->product_type === 'variation') { $selections_in_scenario[$product_id_in_scenario] = WC_CP_Helpers::get_product_variation_title($product_in_scenario); } elseif ($product_in_scenario->product_type === 'variable') { $selections_in_scenario[$product_id_in_scenario] = WC_CP_Helpers::get_product_title($product_in_scenario) . ' ' . __('— All Variations', 'woocommerce-composite-products'); } else { $selections_in_scenario[$product_id_in_scenario] = WC_CP_Helpers::get_product_title($product_in_scenario); } } } } $optional_tip = $component_data['optional'] === 'yes' ? sprintf(__('<br/><strong>Pro Tip</strong>: The <strong>None</strong> option controls the <strong>Optional</strong> property of <strong>%s</strong> in this Scenario.', 'woocommerce-composite-products'), apply_filters('woocommerce_composite_component_title', $component_data['title'], $component_id, $product_id)) : ''; $search_tip = sprintf(__('Search for products and variations from <strong>%1$s</strong>.<br/><strong>Tip</strong>: Choose the <strong>All Products and Variations</strong> option to add all products and variations available under <strong>%1$s</strong> in this Scenario.%2$s', 'woocommerce-composite-products'), apply_filters('woocommerce_composite_component_title', $component_data['title'], $component_id, $product_id), $optional_tip); if (WC_CP_Core_Compatibility::is_wc_version_gte_2_3()) { ?> <input type="hidden" id="bto_scenario_ids_<?php echo $id; ?> _<?php echo $component_id; ?> " name="bto_scenario_data[<?php echo $id; ?> ][component_data][<?php echo $component_id; ?> ]" class="wc-component-options-search" style="width: 75%;" data-component_optional="<?php echo $component_data['optional']; ?> " data-component_id="<?php echo $component_id; ?> " data-placeholder="<?php _e('Search for products & variations…', 'woocommerce-composite-products'); ?> " data-action="woocommerce_json_search_component_options_in_scenario" data-multiple="true" data-selected="<?php echo esc_attr(json_encode($selections_in_scenario)); ?> " value="<?php echo implode(',', array_keys($selections_in_scenario)); ?> " /> <span class="bto_scenario_search tips" data-tip="<?php echo $search_tip; ?> "></span><?php } else { ?> <select id="bto_scenario_ids_<?php echo $id; ?> _<?php echo $component_id; ?> " name="bto_scenario_data[<?php echo $id; ?> ][component_data][<?php echo $component_id; ?> ][]" class="ajax_chosen_select_component_options" multiple="multiple" data-component_optional="<?php echo $component_data['optional']; ?> " data-action="woocommerce_json_search_component_options_in_scenario" data-component_id="<?php echo $component_id; ?> " data-placeholder="<?php echo __('Search for products & variations…', 'woocommerce-composite-products'); ?> "><?php if (!empty($selections_in_scenario)) { foreach ($selections_in_scenario as $selection_id_in_scenario => $selection_in_scenario) { echo '<option value="' . $selection_id_in_scenario . '" selected="selected">' . $selection_in_scenario . '</option>'; } } ?> </select> <span class="bto_scenario_search tips" data-tip="<?php echo $search_tip; ?> "></span><?php } } ?> </div> </div> </div><?php } ?> </div><?php }
/** * @deprecated 3.5.0 */ public function get_product_variation_descriptions($item_id) { _deprecated_function('WC_CP_API::get_product_variation_descriptions()', '3.5.0', 'WC_CP_Helpers::get_product_variation_descriptions()'); return WC_CP_Helpers::get_product_variation_descriptions($item_id); }