/** * Add data for our newly-added custom columns. * @access public * @since 1.0.0 * @param string $column_name * @param int $id * @return void */ public function add_column_data($column_name, $id) { global $wpdb, $post; switch ($column_name) { case 'id': echo $id; break; case 'course-prerequisite': $course_prerequisite_id = get_post_meta($id, '_course_prerequisite', true); if (0 < absint($course_prerequisite_id)) { echo '<a href="' . esc_url(get_edit_post_link(absint($course_prerequisite_id))) . '" title="' . esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($course_prerequisite_id)))) . '">' . get_the_title(absint($course_prerequisite_id)) . '</a>'; } break; case 'course-woocommerce-product': if (WooThemes_Sensei_Utils::sensei_is_woocommerce_activated()) { $course_woocommerce_product_id = get_post_meta($id, '_course_woocommerce_product', true); if (0 < absint($course_woocommerce_product_id)) { if ('product_variation' == get_post_type($course_woocommerce_product_id)) { $product_object = get_product($course_woocommerce_product_id); if (sensei_check_woocommerce_version('2.1')) { $formatted_variation = wc_get_formatted_variation($product_object->variation_data, true); } else { $formatted_variation = woocommerce_get_formatted_variation($product_object->variation_data, true); } $product_name = $product_object->parent->post->post_title . '<br/> ' . ucwords($formatted_variation); } else { $product_name = get_the_title(absint($course_woocommerce_product_id)); } // End If Statement echo '<a href="' . esc_url(get_edit_post_link(absint($course_woocommerce_product_id))) . '" title="' . esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), $product_name)) . '">' . $product_name . '</a>'; } // End If Statement } // End If Statement break; case 'course-category': $output = get_the_term_list($id, 'course-category', '', ', ', ''); if ('' == $output) { $output = __('None', 'woothemes-sensei'); } // End If Statement echo $output; break; default: break; } }
/** * Return a formatted product title based on variation id. * * @param int $item_id * @return string */ public static function get_product_variation_title($variation_id) { if (is_object($variation_id)) { $variation = $variation_id; } else { $variation = wc_get_product($variation_id); } if (!$variation) { return false; } if (WC_CP_Core_Compatibility::is_wc_version_gte_2_5()) { $description = $variation->get_formatted_variation_attributes(true); } else { $description = wc_get_formatted_variation($variation->get_variation_attributes(), true); } $title = $variation->get_title(); $sku = $variation->get_sku(); if ($sku) { $identifier = $sku; } else { $identifier = '#' . $variation->variation_id; } return self::format_product_title($title, $identifier, $description); }
?> <a href="<?php echo get_permalink($oProduct->id); ?> "> <?php echo get_the_title($oProduct->id); ?> </a> <?php } ?> </h4> <div class="uni-wishlist-variation-details"> <?php echo wc_get_formatted_variation($aVarAttrs); ?> </div> <div class="uni-wishlist-item-availability"> <?php $aAvailability = $oProduct->get_availability(); echo '<span class="uni-wishlist-item-avail-' . $aAvailability['class'] . '">' . $aAvailability['availability'] . '</span>'; ?> </div> </div> </td> <td> <?php echo $oProduct->get_price_html(); ?> </td>
} else { ?> <a href="<?php echo esc_url(get_permalink(apply_filters('woocommerce_in_cart_product', $values['prod_id']))); ?> "> <?php echo str_replace(array('http:', 'https:'), '', $thumbnail) . $product_name; ?> </a> <?php } ?> <?php if (!empty($values['variation_id'])) { echo wc_get_formatted_variation(unserialize($values['variation_data']), false); } ?> <?php echo $addons_str; //addon info if (isset($dvin_wcql_settings['no_price']) && $dvin_wcql_settings['no_price'] != 'on') { echo apply_filters('woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf('%s × %s', $values['quantity'], $price_in_html) . '</span>'); ?> <?php } } } ?> </li> <p class="buttons">
</a><br/> <?php if (!empty($values['variation_id'])) { echo wc_get_formatted_variation($product_obj->variation_data, false); } //get price before showing the addon data as proce could change if (!isset($values['price'])) { $values['price'] = get_quotelist_product_price($product_obj); } $temp_arr = array(); if (isset($addon_cart_obj) && $addon_cart_obj instanceof Product_Addon_Cart) { $temp_arr = dvin_wcql_get_add_on_list($addon_cart_obj, $values['price'], $product_obj, $values); } else { $temp_arr = dvin_wcql_get_add_on_list(array(), $values['price'], $product_obj, $values); } echo wc_get_formatted_variation($temp_arr, false); ?> </td> <?php if (!$remove_price_col) { ?> <td class="product-price"> <?php $price_in_html = apply_filters('woocommerce_cart_product_price', wc_price($values['price']), $product_obj); echo apply_filters('woocommerce_cart_item_price', $price_in_html, '', ''); ?> </td> <?php } //end of checking remove price or not if (isset($dvin_wcql_settings['show_sku_col']) && $dvin_wcql_settings['show_sku_col'] == 'on') {
/** * Updates an existing product. * * @since 2.7.0 * @param WC_Product */ public function update(&$product) { $post_data = array('ID' => $product->get_id(), 'post_title' => get_the_title($product->get_parent_id()) . ' – ' . wc_get_formatted_variation($product, true, false), 'post_parent' => $product->get_parent_id(), 'comment_status' => 'closed', 'post_status' => $product->get_status() ? $product->get_status() : 'publish', 'menu_order' => $product->get_menu_order()); wp_update_post($post_data); $this->update_post_meta($product); $this->update_terms($product); $this->update_attributes($product); $product->save_meta_data(); do_action('woocommerce_update_product_variation', $product->get_id()); $product->apply_changes(); $this->update_version_and_type($product); $this->update_term_counts($product); $this->clear_caches($product); }
?> <a href="<?php echo get_permalink($oProduct->id); ?> "> <?php echo get_the_title($oProduct->id); ?> </a> <?php } ?> </h4> <div class="uni-wishlist-variation-details"> <?php echo wc_get_formatted_variation($vat_atts); ?> </div> <div class="uni-wishlist-item-availability"> <?php $aAvailability = $oProduct->get_availability(); echo '<span class="uni-wishlist-item-avail-' . $aAvailability['class'] . '">' . $aAvailability['availability'] . '</span>'; ?> </div> </div> </td> <td> <?php echo $oProduct->get_price_html(); ?> </td>
/** * Order vouchers meta box * * Displays the order vouchers meta box - for showing and modifying * individual vouchers attached to the order * * @since 1.2 */ public function vouchers_meta_box($post) { $order = wc_get_order($post->ID); $order_items = $order->get_items(); ?> <div class="woocommerce_order_vouchers_wrapper"> <table cellpadding="0" cellspacing="0" class="woocommerce_order_vouchers"> <thead> <tr> <th class="thumb" width="1%"><?php _e('Voucher', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="voucher_number"><?php _e('Number', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="sku"><?php _e('SKU', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="data"><?php _e('Data', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="expires"><?php _e('Expires', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="qty"><?php _e('Qty', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="redeem" style="white-space:nowrap;"><?php _e('Mark Redeemed', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> <a class="tips" data-tip="<?php _e('Mark the dates that any vouchers are redeemed. Marking all vouchers redeemed will complete the order.', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> " href="#">[?]</a></th> </tr> </thead> <tbody id="order_vouchers_list"> <?php if (count($order_items) > 0) { foreach ($order_items as $item_id => $item) { // only voucher items if (!isset($item['voucher_id'])) { continue; } $item['voucher_redeem'] = maybe_unserialize($item['voucher_redeem']); $voucher = new WC_Voucher($item['voucher_id'], $post->ID, $item, $item_id); if (isset($item['variation_id']) && $item['variation_id'] > 0) { $_product = wc_get_product($item['variation_id']); } else { $_product = wc_get_product($item['product_id']); } // get any user-supplied voucher data (this includes product variation data and user-entered fields like recipient or message) $voucher_data = array(); if (isset($_product->variation_data)) { $voucher_data = $_product->variation_data; } $voucher_data = array_merge($voucher_data, $voucher->get_user_input_data()); ?> <tr class="item" rel="<?php echo $item_id; ?> "> <td class="thumb"> <a href="<?php echo esc_url(admin_url('post.php?post=' . $voucher->id . '&action=edit')); ?> " class="tips" data-tip="<?php echo '<strong>' . __('Voucher ID:', WC_PDF_Product_Vouchers::TEXT_DOMAIN) . '</strong> ' . $voucher->id; ?> "><?php echo $voucher->get_image(); ?> </a> <?php if ($voucher->file_exists(WC_PDF_Product_Vouchers::get_uploads_path())) { ?> <a href="<?php echo esc_url(add_query_arg(array('action' => 'download', 'product_id' => $item['product_id'], 'item_id' => $item_id, 'voucher_id' => $item['voucher_id']))); ?> "><?php esc_html_e('Download', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </a> <?php } ?> </td> <td class="voucher_number" width="1%"> <?php echo $voucher->get_voucher_number(); ?> </td> <td class="sku" width="1%"> <?php if ($_product->sku) { echo $_product->sku; } else { echo '-'; } ?> </td> <td class="data"> <?php echo $item['name']; ?> <?php if (!empty($voucher_data)) { echo '<br/>' . wc_get_formatted_variation($voucher_data, true); } ?> </td> <td class="expires" style="width:auto;"> <input type="text" name="voucher_expiration[<?php echo $item_id; ?> ]" id="voucher_expiration_<?php echo $item_id; ?> " maxlength="10" value="<?php echo $voucher->expiration_date ? date("Y-m-d", $voucher->expiration_date) : ''; ?> " class="date-picker-field" /> </td> <td class="qty" width="1%"> <?php echo $item['qty']; ?> </td> <td class="redeem" width="1%"> <?php foreach ($item['voucher_redeem'] as $i => $redeem) { ?> <input type="text" name="voucher_redeem[<?php echo $item_id; ?> ][<?php echo $i; ?> ]" id="voucher_redeem_<?php echo $item_id . '_' . $i; ?> " class="voucher_redeem date-picker-field" maxlength="10" style="width:85px;" value="<?php echo $redeem; ?> " class="date-picker-field" /> <?php } ?> </td> </tr> <?php } } ?> </tbody> </table> </div> <p class="buttons buttons-alt"> <button type="button" class="button redeem_all_vouchers"><?php _e('Redeem All ↑', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </button> </p> <div class="clear"></div> <?php }
public function get_contents($order, $package) { $totals = 0; foreach ($package->packed as $key => $item) { $item_ids[] = $item['meta']['id']; } $items = $order->get_items(); $counts = array_count_values($item_ids); foreach ($counts as $key => $qty) { $product = wc_get_product($key); $parent = wc_get_product($product->parent->post->ID); $item = get_post_meta($key); $price = $product->price; $total = $price * $qty; $totals += $total; ?> <tr> <td class="slp_thumb"><?php if ($product) { ?> <a href="<?php echo esc_url(admin_url('post.php?post=' . absint($product->id) . '&action=edit')); ?> " class="tips" data-tip="<?php echo '<strong>' . __('Product ID:', 'slp') . '</strong> ' . absint($product->id); if ($product->variation_id && 'product_variation' === get_post_type($product->variation_id)) { echo '<br/><strong>' . __('Variation ID:', 'slp') . '</strong> ' . absint($product->variation_id); } elseif ($product->variation_id) { echo '<br/><strong>' . __('Variation ID:', 'slp') . '</strong> ' . absint($product->variation_id) . ' (' . __('No longer exists', 'slp') . ')'; } if ($product && $product->get_sku()) { echo '<br/><strong>' . __('Product SKU:', 'slp') . '</strong> ' . esc_html($product->get_sku()); } if ($product && isset($product->variation_data)) { echo '<br/>' . wc_get_formatted_variation($product->variation_data, true); } ?> "> <?php echo $product->get_image('shop_thumbnail', array('title' => '')); ?> </a><?php } else { echo wc_placeholder_img('shop_thumbnail'); } ?> <td><a href="<?php echo admin_url("post.php?post={$product->id}&action=edit"); ?> "><?php echo $product->sku ? $product->sku . ' - ' . $product->post->post_title : $product->post->post_title; ?> </a></td> <td><?php echo $qty; ?> </td> <td style="text-align:right;"><?php echo wc_price($price); ?> </td> <td style="text-align:right;"><?php echo wc_price($total); ?> </td> </tr><?php } ?> <tr> <td colspan="4" style="border-top:1px solid #999; text-align:right;"><?php _e('Package Value', 'slp'); ?> </td> <td style="border-top:1px solid #999; text-align:right;"><?php echo wc_price($totals); ?> </td> </tr> <tr/><?php }
?> <a href="<?php echo esc_url(admin_url('post.php?post=' . absint($_product->id) . '&action=edit')); ?> " class="tips" data-tip="<?php echo '<strong>' . __('Product ID:', 'woocommerce') . '</strong> ' . absint($item['product_id']); if ($item['variation_id'] && 'product_variation' === get_post_type($item['variation_id'])) { echo '<br/><strong>' . __('Variation ID:', 'woocommerce') . '</strong> ' . absint($item['variation_id']); } elseif ($item['variation_id']) { echo '<br/><strong>' . __('Variation ID:', 'woocommerce') . '</strong> ' . absint($item['variation_id']) . ' (' . __('No longer exists', 'woocommerce') . ')'; } if ($_product && $_product->get_sku()) { echo '<br/><strong>' . __('Product SKU:', 'woocommerce') . '</strong> ' . esc_html($_product->get_sku()); } if ($_product && isset($_product->variation_data)) { echo '<br/>' . wc_get_formatted_variation($_product->variation_data, true); } ?> "><?php echo $_product->get_image('shop_thumbnail', array('title' => '')); ?> </a> <?php } else { ?> <?php echo wc_placeholder_img('shop_thumbnail'); ?> <?php } ?>
/** * wcj_order_items_table. */ function wcj_order_items_table($atts, $content = '') { $html = ''; $the_order = $this->the_order; // Get columns $columns = explode('|', $atts['columns']); if (empty($columns)) { return ''; } $columns_total_number = count($columns); // Check all possible args $columns_titles = '' == $atts['columns_titles'] ? array() : explode('|', $atts['columns_titles']); $columns_styles = '' == $atts['columns_styles'] ? array() : explode('|', $atts['columns_styles']); //if ( ! ( $columns_total_number === count( $columns_titles ) === count( $columns_styles ) ) ) return ''; // The Items $the_items = $the_order->get_items(); // Shipping as item if ('' != $atts['shipping_as_item'] && $the_order->get_total_shipping() > 0) { $name = str_replace('%shipping_method_name%', $the_order->get_shipping_method(), $atts['shipping_as_item']); $total_shipping_tax_excl = $the_order->get_total_shipping(); $shipping_tax = $the_order->get_shipping_tax(); $the_items = $this->add_item($the_items, array('name' => $name, 'qty' => 1, 'line_subtotal' => $total_shipping_tax_excl, 'line_total' => $total_shipping_tax_excl, 'line_tax' => $shipping_tax, 'line_subtotal_tax' => $shipping_tax)); } // Discount as item if ('' != $atts['discount_as_item'] && $the_order->get_total_discount(true) > 0) { $name = $atts['discount_as_item']; $total_discount_tax_excl = $the_order->get_total_discount(true); $discount_tax = $the_order->get_total_discount(false) - $total_discount_tax_excl; if (false != ($the_tax = $this->wcj_order_get_cart_discount_tax())) { $total_discount_tax_excl -= $the_tax; $discount_tax += $the_tax; } $total_discount_tax_excl *= -1; $discount_tax *= -1; $the_items = $this->add_item($the_items, array('name' => $name, 'qty' => 1, 'line_subtotal' => $total_discount_tax_excl, 'line_total' => $total_discount_tax_excl, 'line_tax' => $discount_tax, 'line_subtotal_tax' => $discount_tax)); } // Starting data[] by adding columns titles $data = array(); foreach ($columns_titles as $column_title) { $data[0][] = $column_title; } // Items to data[] $item_counter = 0; foreach ($the_items as $item) { $item['is_custom'] = isset($item['is_custom']) ? true : false; $the_product = true === $item['is_custom'] ? null : $the_order->get_product_from_item($item); $item_counter++; // Columns foreach ($columns as $column) { switch ($column) { case 'item_number': $data[$item_counter][] = $item_counter; break; case 'item_name': //$data[ $item_counter ][] = ( true === $item['is_custom'] ) ? $item['name'] : $the_product->get_title(); if (true === $item['is_custom']) { $data[$item_counter][] = $item['name']; } else { $the_item_title = $the_product->get_title(); // Variation (if needed) if ($the_product->is_type('variation') && !in_array('item_variation', $columns)) { $the_item_title .= '<div style="font-size:smaller;">' . wc_get_formatted_variation($the_product->variation_data, true) . '</div>'; } $data[$item_counter][] = $the_item_title; } break; case 'item_variation': $data[$item_counter][] = $the_product->is_type('variation') ? wc_get_formatted_variation($the_product->variation_data, true) : ''; break; case 'item_thumbnail': //$data[ $item_counter ][] = $the_product->get_image(); $image_id = true === $item['is_custom'] ? 0 : $the_product->get_image_id(); $image_src = 0 != $image_id ? wp_get_attachment_image_src($image_id) : wc_placeholder_img_src(); if (is_array($image_src)) { $image_src = $image_src[0]; } $maybe_width = 0 != $atts['item_image_width'] ? ' width="' . $atts['item_image_width'] . '"' : ''; $maybe_height = 0 != $atts['item_image_height'] ? ' height="' . $atts['item_image_height'] . '"' : ''; $data[$item_counter][] = '<img src="' . $image_src . '"' . $maybe_width . $maybe_height . '>'; break; case 'item_sku': $data[$item_counter][] = true === $item['is_custom'] ? '' : $the_product->get_sku(); break; case 'item_quantity': $data[$item_counter][] = $item['qty']; break; case 'item_total_tax_excl': $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_total($item, false, true), $atts); break; case 'item_total_tax_incl': $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_total($item, true, true), $atts); break; case 'item_subtotal_tax_excl': $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_subtotal($item, false, true), $atts); break; case 'item_subtotal_tax_incl': $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_subtotal($item, true, true), $atts); break; case 'item_tax': $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_tax($item, true), $atts); break; case 'line_total_tax_excl': $line_total_tax_excl = $the_order->get_line_total($item, false, true); $line_total_tax_excl = apply_filters('wcj_line_total_tax_excl', $line_total_tax_excl, $the_order); $data[$item_counter][] = $this->wcj_price_shortcode($line_total_tax_excl, $atts); break; case 'line_total_tax_incl': $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_line_total($item, true, true), $atts); break; case 'line_subtotal_tax_excl': $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_line_subtotal($item, false, true), $atts); break; case 'line_subtotal_tax_incl': $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_line_subtotal($item, true, true), $atts); break; case 'line_tax': $line_tax = $the_order->get_line_tax($item); $line_tax = apply_filters('wcj_line_tax', $line_tax, $the_order); $data[$item_counter][] = $this->wcj_price_shortcode($line_tax, $atts); break; case 'line_subtax': $line_subtax = $the_order->get_line_subtotal($item, true, false) - $the_order->get_line_subtotal($item, false, false); $data[$item_counter][] = $this->wcj_price_shortcode($line_subtax, $atts); break; case 'item_tax_percent': case 'line_tax_percent': $item_total = $the_order->get_item_total($item, false, false); $item_tax_percent = 0 != $item_total ? $the_order->get_item_tax($item, false) / $item_total * 100 : 0; $item_tax_percent = apply_filters('wcj_line_tax_percent', $item_tax_percent, $the_order); $data[$item_counter][] = sprintf($atts['tax_percent_format'], $item_tax_percent); /* $tax_labels = array(); foreach ( $the_order->get_taxes() as $the_tax ) { $tax_labels[] = $the_tax['label']; } $data[ $item_counter ][] = implode( ', ', $tax_labels ); */ break; /* case 'line_tax_percent': $line_total = $the_order->get_line_total( $item, false, true ); $line_tax_percent = ( 0 != $line_total ) ? $the_order->get_line_tax( $item ) / $line_total * 100 : 0; $line_tax_percent = apply_filters( 'wcj_line_tax_percent', $line_tax_percent, $the_order ); $data[ $item_counter ][] = sprintf( $atts['tax_percent_format'], $line_tax_percent ); break; */ /* case 'line_tax_percent': $line_total = $the_order->get_line_total( $item, false, true ); $line_tax_percent = ( 0 != $line_total ) ? $the_order->get_line_tax( $item ) / $line_total * 100 : 0; $line_tax_percent = apply_filters( 'wcj_line_tax_percent', $line_tax_percent, $the_order ); $data[ $item_counter ][] = sprintf( $atts['tax_percent_format'], $line_tax_percent ); break; */ default: $data[$item_counter][] = ''; } } } $html = wcj_get_table_html($data, array('table_class' => $atts['table_class'], 'table_heading_type' => 'horizontal', 'columns_classes' => array(), 'columns_styles' => $columns_styles)); return $html; }
} //get price before showing the addon data as proce could change if (!isset($values['price'])) { $unit_price = get_quotelist_product_price($product_obj); } else { $unit_price = $values['price']; } //get price before showing the addon data as proce could change //if addons extensions active if (class_exists('Product_Addon_Cart')) { $addon_cart_obj = new Product_Addon_Cart(); $temp_arr = dvin_wcql_get_add_on_list($addon_cart_obj, $unit_price, $product_obj, $values); } else { $temp_arr = dvin_wcql_get_add_on_list(array(), $unit_price, $product_obj, $values); } $addons_str = wc_get_formatted_variation($temp_arr, false); //if only set the price as visible NOT remove if ($add_price_col == 'on') { $unit_price_in_html = apply_filters('woocommerce_cart_product_price', wc_price($unit_price), $product_obj); $unit_price_in_html = apply_filters('woocommerce_cart_item_price', $unit_price_in_html, '', ''); //decide the quantity $quantity = isset($_POST['qty'][$product_obj->id]) ? $_POST['qty'][$product_obj->id] : $values['quantity']; $total_price = (double) $unit_price * (int) $quantity; $total_price_str = apply_filters('woocommerce_cart_item_price_html', woocommerce_price($total_price)); } else { //decide the quantity $quantity = isset($_POST['qty'][$product_obj->id]) ? $_POST['qty'][$product_obj->id] : $values['quantity']; } //handle hiiden elements/columns $arr = array($href_str, $image_str, $product_name_str . $addons_str); if ($add_sku_toemail == 'on') {
/** * get_items_table. */ public function get_items_table($the_order) { $html = ''; // ITEMS // $the_items = $the_order->get_items(); $html .= '<h2>' . get_option('wcj_pdf_invoices_items_text') . '</h2>'; $html .= '<table class="pdf_invoice_items_table_wcj"><tbody>'; $columns = $this->get_columns(); // Adding to output // $html .= '<tr>'; foreach ($columns as $column) { if (true === $column['required'] || '' != $column['title']) { $html .= '<th style="' . $column['css'] . '">' . $column['title'] . '</th>'; } } $html .= '</tr>'; // Shipping as item $order_total_shipping = $the_order->get_total_shipping(); if ('' != get_option('wcj_pdf_invoices_display_shipping_as_item_text') && $order_total_shipping > 0) { $shipping_item_name = get_option('wcj_pdf_invoices_display_shipping_as_item_text'); // Add shipping method text if ('yes' === get_option('wcj_pdf_invoices_display_shipping_as_item_shipping_method')) { $shipping_item_name .= '<div style="font-size:x-small;">' . $the_order->get_shipping_method() . '</div>'; } else { if ('replace' === get_option('wcj_pdf_invoices_display_shipping_as_item_shipping_method')) { $shipping_item_name = $the_order->get_shipping_method(); } } // Create item $the_items[] = array('name' => $shipping_item_name, 'type' => 'line_item', 'qty' => 1, 'line_subtotal' => $order_total_shipping, 'line_total' => $order_total_shipping, 'line_tax' => $the_order->get_shipping_tax(), 'line_subtotal_tax' => $the_order->get_shipping_tax(), 'item_meta' => array('_qty' => array(1), '_line_subtotal' => array($order_total_shipping), '_line_total' => array($order_total_shipping), '_line_tax' => array($the_order->get_shipping_tax()), '_line_subtotal_tax' => array($the_order->get_shipping_tax()))); } // Discount as item $total_tax_excl = $the_order->get_total_discount(true); if ('' != get_option('wcj_pdf_invoices_display_discount_as_item_text') && 0 != $total_tax_excl) { //$total_tax_excl = $the_order->get_total_discount( true ); $tax = $the_order->get_total_discount(false) - $total_tax_excl; if (false != ($the_tax = $this->wcj_order_get_cart_discount_tax($the_order))) { $total_tax_excl -= $the_tax; $tax += $the_tax; } $total_tax_excl *= -1; $tax *= -1; $the_items[] = array('name' => get_option('wcj_pdf_invoices_display_discount_as_item_text'), 'type' => 'line_item', 'qty' => 1, 'line_subtotal' => $total_tax_excl, 'line_total' => $total_tax_excl, 'line_tax' => $tax, 'line_subtotal_tax' => $tax, 'item_meta' => array('_qty' => array(1), '_line_subtotal' => array($total_tax_excl), '_line_total' => array($total_tax_excl), '_line_tax' => array($tax), '_line_subtotal_tax' => array($tax))); } $order_currency_array = array('currency' => $the_order->get_order_currency()); // ITEMS LOOP // $item_counter = 0; foreach ($the_items as $item) { // Preparing data // // Item Prices $item_total_excl_tax = $the_order->get_item_subtotal($item, false, false); // $item_tax = $the_order->get_item_tax( $item, true ); $item_tax = $the_order->get_item_subtotal($item, true, false) - $the_order->get_item_subtotal($item, false, false); $item_total_incl_tax = $the_order->get_item_subtotal($item, true, false); // Line Prices $line_total_excl_tax = $the_order->get_line_subtotal($item, false, false); $line_tax = $the_order->get_line_subtotal($item, true, false) - $the_order->get_line_subtotal($item, false, false); // $line_tax = $the_order->get_line_tax( $item ); $line_total_incl_tax = $the_order->get_line_subtotal($item, true, false); $line_total_tax_percent = 0; if (0 != $the_order->get_item_total($item, false, false)) { $line_total_tax_percent = $the_order->get_item_tax($item, false) / $the_order->get_item_total($item, false, false) * 100; //round( ( $line_tax / $line_total_excl_tax * 100 ), 2 ); $line_total_tax_percent = sprintf('%.2f %%', $line_total_tax_percent); } $item_total_excl_tax_formatted = wc_price($item_total_excl_tax, $order_currency_array); $item_total_tax_formatted = wc_price($item_tax, $order_currency_array); $item_total_incl_tax_formatted = wc_price($item_total_incl_tax, $order_currency_array); $line_total_excl_tax_formatted = wc_price($line_total_excl_tax, $order_currency_array); $line_total_tax_formatted = wc_price($line_tax, $order_currency_array); $line_total_incl_tax_formatted = wc_price($line_total_incl_tax, $order_currency_array); // Item Quantity $item_quantity = $item['qty']; // Item Name $item_name = $item['name']; //$product->get_title(); $product = $the_order->get_product_from_item($item); if ($product) { // Additional info (e.g. SKU) if ('' != get_option('wcj_pdf_invoices_column_item_name_additional_text') && $product->get_sku()) { $item_name .= ' ' . str_replace('%sku%', $product->get_sku(), get_option('wcj_pdf_invoices_column_item_name_additional_text')); } // Variation (if needed) if ($product->is_type('variation')) { $item_name .= '<div style="font-size:smaller;">' . wc_get_formatted_variation($product->variation_data, true) . '</div>'; } } // Item Counter $item_counter++; // Adding to output // $html .= '<tr>'; foreach ($columns as $column) { if (true === $column['required'] || '' != $column['title']) { $html .= '<td style="' . $column['td_css'] . '">' . ${$column}['value_var'] . '</td>'; } } $html .= '</tr>'; } $html .= '</tbody></table>'; return $html; }
/** * @deprecated */ function woocommerce_get_formatted_variation($variation = '', $flat = false) { return wc_get_formatted_variation($variation, $flat); }
</thead> <tbody> <?php foreach ($shipment->get_items() as $item) { // get the product; if this variation or product has been deleted, this will return null... $_product = $shipment->get_product_from_item($item); $sku = $variation = ''; if ($_product) { $sku = $_product->get_sku(); } $item_meta = new WC_Order_Item_Meta($item['item_meta']); // first, is there order item meta avaialble to display? $variation = $item_meta->display(true, true); if (!$variation && $_product && isset($_product->variation_data)) { // otherwise (for an order added through the admin) lets display the formatted variation data so we have something to fall back to $variation = wc_get_formatted_variation($_product->variation_data, true); } if ($variation) { $variation = '<br/><small>' . $variation . '</small>'; } ?> <tr> <td><?php echo apply_filters('woocommerce_order_product_title', $item['name'], $_product) . $variation; ?> </td> <td align="center"><?php echo $item['qty']; ?> </td> </tr>
/** * Return a formatted product title based on variation id. * * @param int $item_id * @return string */ public function get_product_variation_title($variation_id) { $variation = WC_PB_Core_Compatibility::wc_get_product($variation_id); if (!$variation) { return false; } $description = wc_get_formatted_variation($variation->get_variation_attributes(), true); $title = $variation->get_title(); $sku = $variation->get_sku(); if ($sku) { $sku = sprintf(__('(SKU: %s)', 'woocommerce-product-bundles'), $sku); } return $this->format_product_title($title, $sku, $description); }
/** * Get formatted variation data with WC < 2.4 back compat and proper formatting of text-based attribute names. * * @deprecated 2.7.0 * @return string */ public function get_formatted_variation_attributes($flat = false) { wc_deprecated_function('WC_Product::get_formatted_variation_attributes', '2.7', 'wc_get_formatted_variation'); return wc_get_formatted_variation($this, $flat); }
function fp_rac_get_formatted_variation($variation) { if (function_exists('woocommerce_get_formatted_variation')) { return woocommerce_get_formatted_variation($variation, true); } else { if (function_exists('wc_get_formatted_variation')) { return wc_get_formatted_variation($variation, true); } } }
/** * Renders a table with subscription information. * @param array $options * @param int $n will be set to the number of subscriptions found */ public static function render($options, &$n) { global $wpdb; $output = ''; if (isset($options['user_id'])) { $user = new WP_User($options['user_id']); } else { return $output; } $statuses = array('active'); $show_all = false; if (isset($options['status'])) { $status = $options['status']; if (is_string($status)) { if (trim($status) === '*') { $statuses = array('active', 'on-hold', 'cancelled', 'trash', 'deleted', 'switched'); } else { $statuses = array(); $_statuses = explode(',', $status); foreach ($_statuses as $status) { $status = strtolower(trim($status)); switch ($status) { case 'active': case 'on-hold': case 'cancelled': case 'trash': case 'deleted': case 'switched': $statuses[] = $status; break; } } } } } $exclude_cancelled_after_end_of_prepaid_term = isset($options['exclude_cancelled_after_end_of_prepaid_term']) && ($options['exclude_cancelled_after_end_of_prepaid_term'] === true || $options['exclude_cancelled_after_end_of_prepaid_term'] == 'true' || $options['exclude_cancelled_after_end_of_prepaid_term'] == 'yes'); $include_cancelled_orders = isset($options['include_cancelled_orders']) && ($options['include_cancelled_orders'] === true || $options['include_cancelled_orders'] == 'true' || $options['include_cancelled_orders'] == 'yes'); $include_refunded_orders = isset($options['include_refunded_orders']) && ($options['include_refunded_orders'] === true || $options['include_refunded_orders'] == 'true' || $options['include_refunded_orders'] == 'yes'); if (function_exists('wcs_get_users_subscriptions')) { $results = array(); foreach (wcs_get_users_subscriptions($user->ID) as $subscription) { $results[wcs_get_old_subscription_key($subscription)] = wcs_get_subscription_in_deprecated_structure($subscription); } } else { $results = WC_Subscriptions_Manager::get_users_subscriptions($user->ID); } // pre-filter by status $_results = array(); foreach ($results as $result_key => $result) { $valid = false; if (in_array($result['status'], $statuses)) { $valid = true; } // exclude subscriptions from cancelled or refunded orders if (isset($result['order_id'])) { if ($order = Groups_WS_Helper::get_order($result['order_id'])) { switch ($order->status) { case 'cancelled': if (!$include_cancelled_orders) { $valid = false; } break; case 'refunded': if (!$include_refunded_orders) { $valid = false; } break; } } } if ($exclude_cancelled_after_end_of_prepaid_term && $result['status'] == 'cancelled') { $hook_args = array('user_id' => (int) $user->ID, 'subscription_key' => $result_key); $end_timestamp = wp_next_scheduled('scheduled_subscription_end_of_prepaid_term', $hook_args); if ($end_timestamp === false || $end_timestamp <= time()) { $valid = false; } } if ($valid) { $_results[$result_key] = $result; } } $results = $_results; $n = count($results); if ($n > 0) { $column_display_names = array('status' => __('Status', GROUPS_WS_PLUGIN_DOMAIN), 'title' => __('Subscription', GROUPS_WS_PLUGIN_DOMAIN), 'start_date' => __('Start Date', GROUPS_WS_PLUGIN_DOMAIN), 'expiry_date' => __('Expiration', GROUPS_WS_PLUGIN_DOMAIN), 'end_date' => __('End Date', GROUPS_WS_PLUGIN_DOMAIN), 'trial_expiry_date' => __('Trial Expiration', GROUPS_WS_PLUGIN_DOMAIN), 'groups' => __('Groups', GROUPS_WS_PLUGIN_DOMAIN), 'order_id' => __('Order', GROUPS_WS_PLUGIN_DOMAIN)); if (isset($options['columns']) && $options['columns'] !== null) { if (is_string($options['columns'])) { $columns = explode(',', $options['columns']); $_columns = array(); foreach ($columns as $column) { $_columns[] = trim($column); } $options['columns'] = $_columns; } $new_columns = array(); foreach ($options['columns'] as $key) { if (key_exists($key, $column_display_names)) { $new_columns[$key] = $column_display_names[$key]; } } $column_display_names = $new_columns; } if (count($column_display_names) > 0) { $output .= '<table class="subscriptions">'; $output .= '<thead>'; $output .= '<tr>'; foreach ($column_display_names as $key => $column_display_name) { $output .= "<th scope='col' class='{$key}'>{$column_display_name}</th>"; } $output .= '</tr>'; $output .= '</thead>'; $output .= '<tbody>'; $i = 0; foreach ($results as $result_key => $result) { $order = Groups_WS_Helper::get_order($result['order_id']); if ($order) { $order_item = WC_Subscriptions_Order::get_item_by_product_id($order, $result['product_id']); $product = $order->get_product_from_item($order_item); $output .= '<tr class="' . ($i % 2 == 0 ? 'even' : 'odd') . '">'; foreach ($column_display_names as $column_key => $column_title) { $output .= sprintf('<td class="%s">', $column_key); switch ($column_key) { case 'status': $output .= WC_Subscriptions_Manager::get_status_to_display($result['status'], $result_key, $user->ID); break; case 'title': $output .= WC_Subscriptions_Order::get_item_name($result['order_id'], $result['product_id']); if (isset($product->variation_data)) { $column_content .= '<br />'; if (function_exists('wc_get_formatted_variation')) { $column_content .= wc_get_formatted_variation($product->variation_data, true); } else { $column_content .= woocommerce_get_formatted_variation($product->variation_data, true); } } break; case 'start_date': case 'expiry_date': case 'end_date': if ($column_key == 'expiry_date' && $result[$column_key] == 0) { $output .= __('Never', GROUPS_WS_PLUGIN_DOMAIN); } else { if ($column_key == 'end_date' && $result[$column_key] == 0) { $output .= __('Not yet ended', GROUPS_WS_PLUGIN_DOMAIN); } else { $user_timestamp = strtotime($result[$column_key]) + get_option('gmt_offset') * 3600; $output .= sprintf('<time title="%s">%s</time>', esc_attr($user_timestamp), date_i18n(get_option('date_format'), $user_timestamp)); } } break; case 'trial_expiry_date': $trial_expiration = WC_Subscriptions_Manager::get_trial_expiration_date($result_key, $user->ID, 'timestamp'); if (empty($trial_expiration)) { $output .= '-'; } else { $trial_expiration = $trial_expiration + get_option('gmt_offset') * 3600; $output .= sprintf('<time title="%s">%s</time>', esc_attr($trial_expiration), date_i18n(get_option('date_format'), $trial_expiration)); } break; case 'groups': if ($product_groups = get_post_meta($result['product_id'], '_groups_groups', false)) { if (count($product_groups) > 0) { $output .= '<ul>'; foreach ($product_groups as $group_id) { if ($group = Groups_Group::read($group_id)) { $output .= '<li>' . wp_filter_nohtml_kses($group->name) . '</li>'; } } $output .= '</ul>'; } } break; case 'order_id': $output .= sprintf(__('Order %d', GROUPS_WS_PLUGIN_DOMAIN), $result['order_id']); break; } $output .= '</td>'; } $output .= '</tr>'; $i++; } } $output .= '</tbody>'; $output .= '</table>'; } } return $output; }