/** * Locates the WooCommerce template files from our templates directory * * @since 1.0.0 * @param string $template Already found template * @param string $template_name Searchable template name * @param string $template_path Template path * @return string Search result for the template */ public function locate_template($template, $template_name, $template_path) { // Tmp holder $_template = $template; if (!$template_path) { $template_path = SV_WC_Plugin_Compatibility::is_wc_version_gte_2_2() ? WC()->template_path() : WC_TEMPLATE_PATH; } // Set our base path $plugin_path = wc_product_reviews_pro()->get_plugin_path() . '/templates/'; // Look within passed path within the theme - this is priority $template = locate_template(array(trailingslashit($template_path) . $template_name, $template_name)); // Get the template from this plugin, if it exists if (!$template && file_exists($plugin_path . $template_name)) { $template = $plugin_path . $template_name; } // Use default template if (!$template) { $template = $_template; } // Return what we found return $template; }
/** * Build the formatted_names array for use in displaying on the admin order screen * * @since 1.0 * @param array $items * @param object $order * @return array $items */ public function build_formatted_names($items, $order) { // Bail out if WC 2.2+ if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_2()) { return $items; } // Bail out if not in admin if (!is_admin()) { return $items; } // bail if not on view order screen if (!isset($GLOBALS['current_screen']) || 'shop_order' != $GLOBALS['current_screen']->id) { return $items; } // Check if any of the fees are checkout add-ons foreach ($items as $key => $item) { if ('fee' == $item['type'] && $item['wc_checkout_add_on_id']) { $add_on = wc_checkout_add_ons()->get_add_on($item['wc_checkout_add_on_id']); if ('file' == $add_on->type) { $label = $add_on->normalize_value($item['wc_checkout_add_on_value'], false); $this->file_labels[] = $label; } else { $label = maybe_unserialize($item['wc_checkout_add_on_label']); } if ($label) { $this->formatted_names[$items[$key]['name']] = $items[$key]['name'] . $this->label_separator . (is_array($label) ? implode(', ', $label) : $label); if ('file' != $add_on->type) { $this->formatted_names[$items[$key]['name']] = esc_html($this->formatted_names[$items[$key]['name']]); } } } } return $items; }
/** * Add checkout add-ons values to the order items table * * @param null $_ unused * @param array $item * @since 1.1.0 */ public function add_order_item_values($_, $item, $item_id) { if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_2()) { echo '<td class="wc-checkout-add-ons-value">'; if (is_array($item) && isset($item['wc_checkout_add_on_id']) && ($add_on = $this->get_add_on($item['wc_checkout_add_on_id']))) { $is_editable = in_array($add_on->type, array('text', 'textarea')); if ('file' === $add_on->type) { $value = $add_on->normalize_value($item['wc_checkout_add_on_value'], false); } else { $value = esc_html($add_on->normalize_value(maybe_unserialize($item['wc_checkout_add_on_label']), true)); } ob_start(); ?> <div class="view"> <?php echo $value; ?> </div> <?php if ($is_editable) { ?> <div class="edit" style="display: none;"> <input type="text" placeholder="<?php _e('Checkout Add-on Value', $this->text_domain); ?> " name="checkout_add_on_value[<?php echo $item_id; ?> ]" value="<?php echo $value; ?> " /> <input type="hidden" class="checkout_add_on_id" name="checkout_add_on_item_id[]" value="<?php echo $item_id; ?> " /> <input type="hidden" class="checkout_add_on_id" name="checkout_add_on_id[<?php echo $item_id; ?> ]" value="<?php echo $add_on->id; ?> " /> </div> <?php } ?> <?php echo ob_get_clean(); } echo '</td>'; } }