ThemeUpgrader.php000064400000004004150732347760010025 0ustar00 true, ); $parsed_args = wp_parse_args( $args, $defaults ); $this->init(); $this->install_strings(); add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); add_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ), 10, 3 ); if ( $parsed_args['clear_update_cache'] ) { // Clear cache so wp_update_themes() knows about the new theme. add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 ); } $result = $this->run( array( 'package' => $package, 'destination' => get_theme_root(), 'clear_destination' => false, // Do not overwrite files. 'clear_working' => true, 'hook_extra' => array( 'type' => 'theme', 'action' => 'install', ), ) ); remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 ); remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) ); if ( $result && ! is_wp_error( $result ) ) { // Refresh the Theme Update information. wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); } return $result; } } ThemeUpgraderSkin.php000064400000001446150732347760010661 0ustar00get_quantity( 'edit' ); $order_items = $this->get_item_count(); if ( 0 === $order_items ) { return 0; } $total_shipping_amount = (float) $this->get_shipping_total(); return $total_shipping_amount / $order_items * $product_qty; } /** * Calculate shipping tax amount for line item/product as a total shipping tax amount ratio based on quantity. * * Loosely based on code in includes/admin/meta-boxes/views/html-order-item(s).php. * * @todo If WC is currently not tax enabled, but it was before (or vice versa), would this work correctly? * * @param WC_Order_Item $item Line item from order. * * @return float|int */ public function get_item_shipping_tax_amount( $item ) { $order_items = $this->get_item_count(); if ( 0 === $order_items ) { return 0; } $product_qty = $item->get_quantity( 'edit' ); $order_taxes = $this->get_taxes(); $line_items_shipping = $this->get_items( 'shipping' ); $total_shipping_tax_amount = 0; foreach ( $line_items_shipping as $item_id => $shipping_item ) { $tax_data = $shipping_item->get_taxes(); if ( $tax_data ) { foreach ( $order_taxes as $tax_item ) { $tax_item_id = $tax_item->get_rate_id(); $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? (float) $tax_data['total'][ $tax_item_id ] : 0; $total_shipping_tax_amount += $tax_item_total; } } } return $total_shipping_tax_amount / $order_items * $product_qty; } /** * Calculates coupon amount for specified line item/product. * * Coupon calculation based on woocommerce code in includes/admin/meta-boxes/views/html-order-item.php. * * @param WC_Order_Item $item Line item from order. * * @return float */ public function get_item_coupon_amount( $item ) { return floatval( $item->get_subtotal( 'edit' ) - $item->get_total( 'edit' ) ); } } OrderRefund.php000064400000004034150732347760007513 0ustar00customer_id ) ) { $parent_order = \wc_get_order( $this->get_parent_id() ); if ( ! $parent_order ) { $this->customer_id = false; } $this->customer_id = CustomersDataStore::get_or_create_customer_from_order( $parent_order ); } return $this->customer_id; } /** * Returns null since refunds should not be counted towards returning customer counts. * * @return null */ public function is_returning_customer() { return null; } } Order.php000064400000007123150732347760006351 0ustar00 $this->get_id(), ), $this->data, array( 'number' => $this->get_order_number(), 'meta_data' => $this->get_meta_data(), ) ); } /** * Get order line item data by type. * * @param string $type Order line item type. * @return array|bool Array of line items on success, boolean false on failure. */ public function get_line_item_data( $type ) { $type_to_items = array( 'line_items' => 'line_item', 'tax_lines' => 'tax', 'shipping_lines' => 'shipping', 'fee_lines' => 'fee', 'coupon_lines' => 'coupon', ); if ( isset( $type_to_items[ $type ] ) ) { return $this->get_items( $type_to_items[ $type ] ); } return false; } /** * Add filter(s) required to hook this class to substitute WC_Order. */ public static function add_filters() { add_filter( 'woocommerce_order_class', array( __CLASS__, 'order_class_name' ), 10, 3 ); } /** * Filter function to swap class WC_Order for this one in cases when it's suitable. * * @param string $classname Name of the class to be created. * @param string $order_type Type of order object to be created. * @param number $order_id Order id to create. * * @return string */ public static function order_class_name( $classname, $order_type, $order_id ) { // @todo - Only substitute class when necessary (during sync). if ( 'WC_Order' === $classname ) { return '\Automattic\WooCommerce\Admin\Overrides\Order'; } else { return $classname; } } /** * Get the customer ID used for reports in the customer lookup table. * * @return int */ public function get_report_customer_id() { if ( is_null( $this->customer_id ) ) { $this->customer_id = CustomersDataStore::get_or_create_customer_from_order( $this ); } return $this->customer_id; } /** * Returns true if the customer has made an earlier order. * * @return bool */ public function is_returning_customer() { return OrdersStatsDataStore::is_returning_customer( $this, $this->get_report_customer_id() ); } /** * Get the customer's first name. */ public function get_customer_first_name() { if ( $this->get_user_id() ) { return get_user_meta( $this->get_user_id(), 'first_name', true ); } if ( '' !== $this->get_billing_first_name( 'edit' ) ) { return $this->get_billing_first_name( 'edit' ); } else { return $this->get_shipping_first_name( 'edit' ); } } /** * Get the customer's last name. */ public function get_customer_last_name() { if ( $this->get_user_id() ) { return get_user_meta( $this->get_user_id(), 'last_name', true ); } if ( '' !== $this->get_billing_last_name( 'edit' ) ) { return $this->get_billing_last_name( 'edit' ); } else { return $this->get_shipping_last_name( 'edit' ); } } }