/** * Backports wc_help_tip() to WC 2.4/2.3 * * @link https://github.com/woothemes/woocommerce/pull/9417 * * @since 4.2.0 * @param string $tip help tip content, HTML allowed if $has_html is true * @param bool $has_html false by default, true to indicate tip content has HTML * @return string help tip HTML, a <span> in WC 2.5, <img> in WC 2.4/2.3 */ public static function wc_help_tip($tip, $has_html = false) { if (self::is_wc_version_gte_2_5()) { return wc_help_tip($tip, $has_html); } else { $tip = $has_html ? wc_sanitize_tooltip($tip) : esc_attr($tip); return sprintf('<img class="help_tip" data-tip="%1$s" src="%2$s" height="16" width="16" />', $tip, esc_url(WC()->plugin_url()) . '/assets/images/help.png'); } }
/** * Output custom columns for coupons * @param string $column */ public function render_shop_order_columns($column) { global $post, $woocommerce, $the_order; if (empty($the_order) || $the_order->id != $post->ID) { $the_order = wc_get_order($post->ID); } switch ($column) { case 'order_status': printf('<mark class="%s tips" data-tip="%s">%s</mark>', sanitize_title($the_order->get_status()), wc_get_order_status_name($the_order->get_status()), wc_get_order_status_name($the_order->get_status())); break; case 'order_date': if ('0000-00-00 00:00:00' == $post->post_date) { $t_time = $h_time = __('Unpublished', 'woocommerce'); } else { $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post); $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post); } echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('post_date_column_time', $h_time, $post)) . '</abbr>'; break; case 'customer_message': if ($the_order->customer_message) { echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip($the_order->customer_message) . '">' . __('Yes', 'woocommerce') . '</span>'; } else { echo '<span class="na">–</span>'; } break; case 'order_items': echo '<a href="#" class="show_order_items">' . apply_filters('woocommerce_admin_order_item_count', sprintf(_n('%d item', '%d items', $the_order->get_item_count(), 'woocommerce'), $the_order->get_item_count()), $the_order) . '</a>'; if (sizeof($the_order->get_items()) > 0) { echo '<table class="order_items" cellspacing="0">'; foreach ($the_order->get_items() as $item) { $product = apply_filters('woocommerce_order_item_product', $the_order->get_product_from_item($item), $item); $item_meta = new WC_Order_Item_Meta($item, $product); $item_meta_html = $item_meta->display(true, true); ?> <tr class="<?php echo apply_filters('woocommerce_admin_order_item_class', '', $item); ?> "> <td class="qty"><?php echo absint($item['qty']); ?> </td> <td class="name"> <?php if ($product) { ?> <?php echo wc_product_sku_enabled() && $product->get_sku() ? $product->get_sku() . ' - ' : ''; ?> <a href="<?php echo get_edit_post_link($product->id); ?> " title="<?php echo apply_filters('woocommerce_order_item_name', $item['name'], $item, false); ?> "><?php echo apply_filters('woocommerce_order_item_name', $item['name'], $item, false); ?> </a> <?php } else { ?> <?php echo apply_filters('woocommerce_order_item_name', $item['name'], $item, false); ?> <?php } ?> <?php if (!empty($item_meta_html)) { ?> <a class="tips" href="#" data-tip="<?php echo esc_attr($item_meta_html); ?> ">[?]</a> <?php } ?> </td> </tr> <?php } echo '</table>'; } else { echo '–'; } break; case 'shipping_address': if ($address = $the_order->get_formatted_shipping_address()) { echo '<a target="_blank" href="' . esc_url($the_order->get_shipping_address_map_url()) . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $address)) . '</a>'; } else { echo '–'; } if ($the_order->get_shipping_method()) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->get_shipping_method()) . '</small>'; } break; case 'order_notes': if ($post->comment_count) { // check the status of the post $status = 'trash' !== $post->post_status ? '' : 'post-trashed'; $latest_notes = get_comments(array('post_id' => $post->ID, 'number' => 1, 'status' => $status)); $latest_note = current($latest_notes); if ($post->comment_count == 1) { echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip($latest_note->comment_content) . '">' . __('Yes', 'woocommerce') . '</span>'; } elseif (isset($latest_note->comment_content)) { echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip($latest_note->comment_content . '<br/><small style="display:block">' . sprintf(_n('plus %d other note', 'plus %d other notes', $post->comment_count - 1, 'woocommerce'), $post->comment_count - 1) . '</small>') . '">' . __('Yes', 'woocommerce') . '</span>'; } else { echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip(sprintf(_n('%d note', '%d notes', $post->comment_count, 'woocommerce'), $post->comment_count)) . '">' . __('Yes', 'woocommerce') . '</span>'; } } else { echo '<span class="na">–</span>'; } break; case 'order_total': echo $the_order->get_formatted_order_total(); if ($the_order->payment_method_title) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->payment_method_title) . '</small>'; } break; case 'order_title': $customer_tip = array(); if ($address = $the_order->get_formatted_billing_address()) { $customer_tip[] = __('Billing:', 'woocommerce') . ' ' . $address . '<br/><br/>'; } if ($the_order->billing_phone) { $customer_tip[] = __('Tel:', 'woocommerce') . ' ' . $the_order->billing_phone; } if ($the_order->user_id) { $user_info = get_userdata($the_order->user_id); } if (!empty($user_info)) { $username = '******' . absint($user_info->ID) . '">'; if ($user_info->first_name || $user_info->last_name) { $username .= esc_html(ucfirst($user_info->first_name) . ' ' . ucfirst($user_info->last_name)); } else { $username .= esc_html(ucfirst($user_info->display_name)); } $username .= '</a>'; } else { if ($the_order->billing_first_name || $the_order->billing_last_name) { $username = trim($the_order->billing_first_name . ' ' . $the_order->billing_last_name); } else { $username = __('Guest', 'woocommerce'); } } printf(_x('%s by %s', 'Order number by X', 'woocommerce'), '<a href="' . admin_url('post.php?post=' . absint($post->ID) . '&action=edit') . '" class="row-title"><strong>#' . esc_attr($the_order->get_order_number()) . '</strong></a>', $username); if ($the_order->billing_email) { echo '<small class="meta email"><a href="' . esc_url('mailto:' . $the_order->billing_email) . '">' . esc_html($the_order->billing_email) . '</a></small>'; } echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __('Show more details', 'woocommerce') . '</span></button>'; break; case 'order_actions': ?> <p> <?php do_action('woocommerce_admin_order_actions_start', $the_order); $actions = array(); if ($the_order->has_status(array('pending', 'on-hold'))) { $actions['processing'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $post->ID), 'woocommerce-mark-order-status'), 'name' => __('Processing', 'woocommerce'), 'action' => "processing"); } if ($the_order->has_status(array('pending', 'on-hold', 'processing'))) { $actions['complete'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $post->ID), 'woocommerce-mark-order-status'), 'name' => __('Complete', 'woocommerce'), 'action' => "complete"); } $actions['view'] = array('url' => admin_url('post.php?post=' . $post->ID . '&action=edit'), 'name' => __('View', 'woocommerce'), 'action' => "view"); $actions = apply_filters('woocommerce_admin_order_actions', $actions, $the_order); foreach ($actions as $action) { printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name'])); } do_action('woocommerce_admin_order_actions_end', $the_order); ?> </p><?php break; } }
/** * Get HTML for tooltips * * @param array $data * @return string */ public function get_tooltip_html($data) { if ($data['desc_tip'] === true) { $tip = $data['description']; } elseif (!empty($data['desc_tip'])) { $tip = $data['desc_tip']; } else { $tip = ''; } return $tip ? '<img class="help_tip" data-tip="' . wc_sanitize_tooltip($tip) . '" src="' . WC()->plugin_url() . '/assets/images/help.png" height="16" width="16" />' : ''; }
/** * Display a WooCommerce help tip. * * @since 2.5.0 * * @param string $tip Help tip text * @param bool $allow_html Allow sanitized HTML if true or escape * @return string */ function wc_help_tip($tip, $allow_html = false) { if ($allow_html) { $tip = wc_sanitize_tooltip($tip); } else { $tip = esc_attr($tip); } return '<span class="woocommerce-help-tip" data-tip="' . $tip . '"></span>'; }
/** * Test wc_sanitize_tooltip() - note this is a basic type test as WP core already. * has coverage for wp_kses(). * * @since 2.4 */ public function test_wc_sanitize_tooltip() { $this->assertEquals('alert();cleaned', wc_sanitize_tooltip('<script>alert();</script>cleaned')); }
public function render_shop_order_columns($column) { global $post, $woocommerce, $the_order; if (empty($the_order) || $the_order->id != $post->ID) { $the_order = wc_get_order($post->ID); } switch ($column) { case 'order_title': $crm_customer_link = get_option('wc_crm_customer_link', 'customer'); if ($crm_customer_link == 'customer') { $url = ''; $customer_tip = array(); if ($address = $the_order->get_formatted_billing_address()) { $customer_tip[] = __('Billing:', 'woocommerce') . ' ' . $address . '<br/><br/>'; } if ($the_order->billing_phone) { $customer_tip[] = __('Tel:', 'woocommerce') . ' ' . $the_order->billing_phone; } echo '<div class="tips wc_crm_customer_link" data-tip="' . wc_sanitize_tooltip(implode("<br/>", $customer_tip)) . '">'; $user_id = $the_order->user_id; $email = $the_order->billing_email; if ($user_id) { $user = wc_crm_get_customer($user_id, 'user_id'); if ($user) { $url = get_admin_url() . 'admin.php?page=' . WC_CRM_TOKEN . '&c_id=' . $user->c_id; } } else { if ($email) { $user = wc_crm_get_customer($email); if ($user) { $url = get_admin_url() . 'admin.php?page=' . WC_CRM_TOKEN . '&c_id=' . $user->c_id; } } } $username = ''; if (!empty($url) && $user) { $username = '******' . $url . '">'; if ($user->first_name || $user->last_name) { $username .= esc_html(ucfirst($user->first_name) . ' ' . ucfirst($user->last_name)); } else { if ($the_order->user_id) { $user_info = get_userdata($the_order->user_id); } if (!empty($user_info)) { $username .= esc_html(ucfirst($user_info->display_name)); } else { $username = __('Guest', 'woocommerce'); } } $username .= '</a>'; } printf(_x('%s by %s', 'Order number by X', 'woocommerce'), '<a href="' . admin_url('post.php?post=' . absint($post->ID) . '&action=edit') . '" class="row-title"><strong>#' . esc_attr($the_order->get_order_number()) . '</strong></a>', $username); if ($the_order->billing_email) { echo '<small class="meta email"><a href="' . esc_url('mailto:' . $the_order->billing_email) . '">' . esc_html($the_order->billing_email) . '</a></small>'; } echo '</div>'; } break; } }