Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../includes/admin
File: wc-admin-functions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WooCommerce Admin Functions
[2] Fix | Delete
*
[3] Fix | Delete
* @package WooCommerce\Admin\Functions
[4] Fix | Delete
* @version 2.4.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
use Automattic\WooCommerce\Enums\OrderStatus;
[8] Fix | Delete
use Automattic\WooCommerce\Utilities\OrderUtil;
[9] Fix | Delete
[10] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[11] Fix | Delete
exit;
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Get all WooCommerce screen ids.
[16] Fix | Delete
*
[17] Fix | Delete
* @return array
[18] Fix | Delete
*/
[19] Fix | Delete
function wc_get_screen_ids() {
[20] Fix | Delete
$wc_screen_id = 'woocommerce';
[21] Fix | Delete
$screen_ids = array(
[22] Fix | Delete
'toplevel_page_' . $wc_screen_id,
[23] Fix | Delete
$wc_screen_id . '_page_wc-orders',
[24] Fix | Delete
$wc_screen_id . '_page_wc-reports',
[25] Fix | Delete
$wc_screen_id . '_page_wc-shipping',
[26] Fix | Delete
$wc_screen_id . '_page_wc-settings',
[27] Fix | Delete
$wc_screen_id . '_page_wc-status',
[28] Fix | Delete
$wc_screen_id . '_page_wc-addons',
[29] Fix | Delete
'toplevel_page_wc-reports',
[30] Fix | Delete
'product_page_product_attributes',
[31] Fix | Delete
'product_page_product_exporter',
[32] Fix | Delete
'product_page_product_importer',
[33] Fix | Delete
'product_page_product-reviews',
[34] Fix | Delete
'edit-product',
[35] Fix | Delete
'product',
[36] Fix | Delete
'edit-shop_coupon',
[37] Fix | Delete
'shop_coupon',
[38] Fix | Delete
'edit-product_cat',
[39] Fix | Delete
'edit-product_tag',
[40] Fix | Delete
'profile',
[41] Fix | Delete
'user-edit',
[42] Fix | Delete
);
[43] Fix | Delete
[44] Fix | Delete
foreach ( wc_get_order_types() as $type ) {
[45] Fix | Delete
$screen_ids[] = $type;
[46] Fix | Delete
$screen_ids[] = 'edit-' . $type;
[47] Fix | Delete
$screen_ids[] = wc_get_page_screen_id( $type );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$attributes = wc_get_attribute_taxonomies();
[51] Fix | Delete
[52] Fix | Delete
if ( $attributes ) {
[53] Fix | Delete
foreach ( $attributes as $attribute ) {
[54] Fix | Delete
$screen_ids[] = 'edit-' . wc_attribute_taxonomy_name( $attribute->attribute_name );
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
[59] Fix | Delete
return apply_filters( 'woocommerce_screen_ids', $screen_ids );
[60] Fix | Delete
/* phpcs: enable */
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Get page ID for a specific WC resource.
[65] Fix | Delete
*
[66] Fix | Delete
* @param string $for Name of the resource.
[67] Fix | Delete
*
[68] Fix | Delete
* @return string Page ID. Empty string if resource not found.
[69] Fix | Delete
*/
[70] Fix | Delete
function wc_get_page_screen_id( $for ) {
[71] Fix | Delete
$screen_id = '';
[72] Fix | Delete
$for = str_replace( '-', '_', $for );
[73] Fix | Delete
[74] Fix | Delete
if ( in_array( $for, wc_get_order_types( 'admin-menu' ), true ) ) {
[75] Fix | Delete
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
[76] Fix | Delete
$screen_id = 'woocommerce_page_wc-orders' . ( 'shop_order' === $for ? '' : '--' . $for );
[77] Fix | Delete
} else {
[78] Fix | Delete
$screen_id = $for;
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
return $screen_id;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Create a page and store the ID in an option.
[87] Fix | Delete
*
[88] Fix | Delete
* @param mixed $slug Slug for the new page.
[89] Fix | Delete
* @param string $option Option name to store the page's ID.
[90] Fix | Delete
* @param string $page_title (default: '') Title for the new page.
[91] Fix | Delete
* @param string $page_content (default: '') Content for the new page.
[92] Fix | Delete
* @param int $post_parent (default: 0) Parent for the new page.
[93] Fix | Delete
* @param string $post_status (default: publish) The post status of the new page.
[94] Fix | Delete
* @return int page ID.
[95] Fix | Delete
*/
[96] Fix | Delete
function wc_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0, $post_status = 'publish' ) {
[97] Fix | Delete
global $wpdb;
[98] Fix | Delete
[99] Fix | Delete
$option_value = get_option( $option );
[100] Fix | Delete
[101] Fix | Delete
if ( $option_value > 0 ) {
[102] Fix | Delete
$page_object = get_post( $option_value );
[103] Fix | Delete
[104] Fix | Delete
if ( $page_object && 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ), true ) ) {
[105] Fix | Delete
// Valid page is already in place.
[106] Fix | Delete
return $page_object->ID;
[107] Fix | Delete
}
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
if ( strlen( $page_content ) > 0 ) {
[111] Fix | Delete
// Search for an existing page with the specified page content (typically a shortcode).
[112] Fix | Delete
$shortcode = str_replace( array( '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ), '', $page_content );
[113] Fix | Delete
$valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$shortcode}%" ) );
[114] Fix | Delete
} else {
[115] Fix | Delete
// Search for an existing page with the specified page slug.
[116] Fix | Delete
$valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) );
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
[120] Fix | Delete
$valid_page_found = apply_filters( 'woocommerce_create_page_id', $valid_page_found, $slug, $page_content );
[121] Fix | Delete
/* phpcs: enable */
[122] Fix | Delete
[123] Fix | Delete
if ( $valid_page_found ) {
[124] Fix | Delete
if ( $option ) {
[125] Fix | Delete
update_option( $option, $valid_page_found );
[126] Fix | Delete
}
[127] Fix | Delete
return $valid_page_found;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
// Search for a matching valid trashed page.
[131] Fix | Delete
if ( strlen( $page_content ) > 0 ) {
[132] Fix | Delete
// Search for an existing page with the specified page content (typically a shortcode).
[133] Fix | Delete
$trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
[134] Fix | Delete
} else {
[135] Fix | Delete
// Search for an existing page with the specified page slug.
[136] Fix | Delete
$trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
if ( $trashed_page_found ) {
[140] Fix | Delete
$page_id = $trashed_page_found;
[141] Fix | Delete
$page_data = array(
[142] Fix | Delete
'ID' => $page_id,
[143] Fix | Delete
'post_status' => $post_status,
[144] Fix | Delete
);
[145] Fix | Delete
wp_update_post( $page_data );
[146] Fix | Delete
} else {
[147] Fix | Delete
$page_data = array(
[148] Fix | Delete
'post_status' => $post_status,
[149] Fix | Delete
'post_type' => 'page',
[150] Fix | Delete
'post_author' => 1,
[151] Fix | Delete
'post_name' => $slug,
[152] Fix | Delete
'post_title' => $page_title,
[153] Fix | Delete
'post_content' => $page_content,
[154] Fix | Delete
'post_parent' => $post_parent,
[155] Fix | Delete
'comment_status' => 'closed',
[156] Fix | Delete
);
[157] Fix | Delete
$page_id = wp_insert_post( $page_data );
[158] Fix | Delete
[159] Fix | Delete
/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
[160] Fix | Delete
do_action( 'woocommerce_page_created', $page_id, $page_data );
[161] Fix | Delete
/* phpcs: enable */
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
if ( $option ) {
[165] Fix | Delete
update_option( $option, $page_id );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
return $page_id;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Output admin fields.
[173] Fix | Delete
*
[174] Fix | Delete
* Loops through the woocommerce options array and outputs each field.
[175] Fix | Delete
*
[176] Fix | Delete
* @param array $options Opens array to output.
[177] Fix | Delete
*/
[178] Fix | Delete
function woocommerce_admin_fields( $options ) {
[179] Fix | Delete
[180] Fix | Delete
if ( ! class_exists( 'WC_Admin_Settings', false ) ) {
[181] Fix | Delete
include dirname( __FILE__ ) . '/class-wc-admin-settings.php';
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
WC_Admin_Settings::output_fields( $options );
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
/**
[188] Fix | Delete
* Update all settings which are passed.
[189] Fix | Delete
*
[190] Fix | Delete
* @param array $options Option fields to save.
[191] Fix | Delete
* @param array $data Passed data.
[192] Fix | Delete
*/
[193] Fix | Delete
function woocommerce_update_options( $options, $data = null ) {
[194] Fix | Delete
[195] Fix | Delete
if ( ! class_exists( 'WC_Admin_Settings', false ) ) {
[196] Fix | Delete
include dirname( __FILE__ ) . '/class-wc-admin-settings.php';
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
WC_Admin_Settings::save_fields( $options, $data );
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
/**
[203] Fix | Delete
* Get a setting from the settings API.
[204] Fix | Delete
*
[205] Fix | Delete
* @param mixed $option_name Option name to save.
[206] Fix | Delete
* @param mixed $default Default value to save.
[207] Fix | Delete
* @return string
[208] Fix | Delete
*/
[209] Fix | Delete
function woocommerce_settings_get_option( $option_name, $default = '' ) {
[210] Fix | Delete
[211] Fix | Delete
if ( ! class_exists( 'WC_Admin_Settings', false ) ) {
[212] Fix | Delete
include dirname( __FILE__ ) . '/class-wc-admin-settings.php';
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
return WC_Admin_Settings::get_option( $option_name, $default );
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Sees if line item stock has already reduced stock, and whether those values need adjusting e.g. after changing item qty.
[220] Fix | Delete
*
[221] Fix | Delete
* @since 3.6.0
[222] Fix | Delete
* @param WC_Order_Item $item Item object.
[223] Fix | Delete
* @param integer $item_quantity Optional quantity to check against. Read from object if not passed.
[224] Fix | Delete
* @return boolean|array|WP_Error Array of changes or error object when stock is updated (@see wc_update_product_stock). False if nothing changes.
[225] Fix | Delete
*/
[226] Fix | Delete
function wc_maybe_adjust_line_item_product_stock( $item, $item_quantity = -1 ) {
[227] Fix | Delete
if ( 'line_item' !== $item->get_type() ) {
[228] Fix | Delete
return false;
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
/**
[232] Fix | Delete
* Prevent adjust line item product stock.
[233] Fix | Delete
*
[234] Fix | Delete
* @since 3.7.1
[235] Fix | Delete
* @param bool $prevent If should prevent.
[236] Fix | Delete
* @param WC_Order_Item $item Item object.
[237] Fix | Delete
* @param int $item_quantity Optional quantity to check against.
[238] Fix | Delete
*/
[239] Fix | Delete
if ( apply_filters( 'woocommerce_prevent_adjust_line_item_product_stock', false, $item, $item_quantity ) ) {
[240] Fix | Delete
return false;
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
$product = $item->get_product();
[244] Fix | Delete
[245] Fix | Delete
if ( ! $product || ! $product->managing_stock() ) {
[246] Fix | Delete
return false;
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
$item_quantity = wc_stock_amount( $item_quantity >= 0 ? $item_quantity : $item->get_quantity() );
[250] Fix | Delete
$already_reduced_stock = wc_stock_amount( $item->get_meta( '_reduced_stock', true ) );
[251] Fix | Delete
$restock_refunded_items = wc_stock_amount( $item->get_meta( '_restock_refunded_items', true ) );
[252] Fix | Delete
[253] Fix | Delete
$diff = $item_quantity - $restock_refunded_items - $already_reduced_stock;
[254] Fix | Delete
[255] Fix | Delete
/*
[256] Fix | Delete
* 0 as $item_quantity usually indicates we're deleting the order item.
[257] Fix | Delete
* Let's restore back the reduced count.
[258] Fix | Delete
*/
[259] Fix | Delete
if ( 0 === $item_quantity ) {
[260] Fix | Delete
$diff = $already_reduced_stock * -1;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
if ( $diff < 0 ) {
[264] Fix | Delete
$new_stock = wc_update_product_stock( $product, $diff * -1, 'increase' );
[265] Fix | Delete
} elseif ( $diff > 0 ) {
[266] Fix | Delete
$new_stock = wc_update_product_stock( $product, $diff, 'decrease' );
[267] Fix | Delete
} else {
[268] Fix | Delete
return false;
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
if ( is_wp_error( $new_stock ) ) {
[272] Fix | Delete
return $new_stock;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
$item->update_meta_data( '_reduced_stock', $item_quantity - $restock_refunded_items );
[276] Fix | Delete
$item->save();
[277] Fix | Delete
[278] Fix | Delete
if ( $item_quantity > 0 ) {
[279] Fix | Delete
// If stock was reduced, then we need to mark this on parent order object as well so that cancel logic works properly.
[280] Fix | Delete
$order_data_store = WC_Data_Store::load( 'order' );
[281] Fix | Delete
if ( $item->get_order_id() && ! $order_data_store->get_stock_reduced( $item->get_order_id() ) ) {
[282] Fix | Delete
$order_data_store->set_stock_reduced( $item->get_order_id(), true );
[283] Fix | Delete
}
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
return array(
[287] Fix | Delete
'from' => $new_stock + $diff,
[288] Fix | Delete
'to' => $new_stock,
[289] Fix | Delete
);
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* Save order items. Uses the CRUD.
[294] Fix | Delete
*
[295] Fix | Delete
* @since 2.2
[296] Fix | Delete
* @param int $order_id Order ID.
[297] Fix | Delete
* @param array $items Order items to save.
[298] Fix | Delete
*/
[299] Fix | Delete
function wc_save_order_items( $order_id, $items ) {
[300] Fix | Delete
// Allow other plugins to check change in order items before they are saved.
[301] Fix | Delete
/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
[302] Fix | Delete
do_action( 'woocommerce_before_save_order_items', $order_id, $items );
[303] Fix | Delete
/* phpcs: enable */
[304] Fix | Delete
[305] Fix | Delete
$qty_change_order_notes = array();
[306] Fix | Delete
$order = wc_get_order( $order_id );
[307] Fix | Delete
[308] Fix | Delete
// Line items and fees.
[309] Fix | Delete
if ( isset( $items['order_item_id'] ) ) {
[310] Fix | Delete
$data_keys = array(
[311] Fix | Delete
'line_tax' => array(),
[312] Fix | Delete
'line_subtotal_tax' => array(),
[313] Fix | Delete
'order_item_name' => null,
[314] Fix | Delete
'order_item_qty' => null,
[315] Fix | Delete
'order_item_tax_class' => null,
[316] Fix | Delete
'line_total' => null,
[317] Fix | Delete
'line_subtotal' => null,
[318] Fix | Delete
);
[319] Fix | Delete
foreach ( $items['order_item_id'] as $item_id ) {
[320] Fix | Delete
$item = WC_Order_Factory::get_order_item( absint( $item_id ) );
[321] Fix | Delete
[322] Fix | Delete
if ( ! $item ) {
[323] Fix | Delete
continue;
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
$item_data = array();
[327] Fix | Delete
[328] Fix | Delete
foreach ( $data_keys as $key => $default ) {
[329] Fix | Delete
$item_data[ $key ] = isset( $items[ $key ][ $item_id ] ) ? wc_check_invalid_utf8( wp_unslash( $items[ $key ][ $item_id ] ) ) : $default;
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
if ( '0' === $item_data['order_item_qty'] ) {
[333] Fix | Delete
$changed_stock = wc_maybe_adjust_line_item_product_stock( $item, 0 );
[334] Fix | Delete
if ( $changed_stock && ! is_wp_error( $changed_stock ) ) {
[335] Fix | Delete
$qty_change_order_notes[] = $item->get_name() . ' &ndash; ' . $changed_stock['from'] . '&rarr;' . $changed_stock['to'];
[336] Fix | Delete
}
[337] Fix | Delete
$item->delete();
[338] Fix | Delete
continue;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
$item->set_props(
[342] Fix | Delete
array(
[343] Fix | Delete
'name' => $item_data['order_item_name'],
[344] Fix | Delete
'quantity' => $item_data['order_item_qty'],
[345] Fix | Delete
'tax_class' => $item_data['order_item_tax_class'],
[346] Fix | Delete
'total' => $item_data['line_total'],
[347] Fix | Delete
'subtotal' => $item_data['line_subtotal'],
[348] Fix | Delete
'taxes' => array(
[349] Fix | Delete
'total' => $item_data['line_tax'],
[350] Fix | Delete
'subtotal' => $item_data['line_subtotal_tax'],
[351] Fix | Delete
),
[352] Fix | Delete
)
[353] Fix | Delete
);
[354] Fix | Delete
[355] Fix | Delete
if ( 'fee' === $item->get_type() ) {
[356] Fix | Delete
$item->set_amount( $item_data['line_total'] );
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
if ( isset( $items['meta_key'][ $item_id ], $items['meta_value'][ $item_id ] ) ) {
[360] Fix | Delete
foreach ( $items['meta_key'][ $item_id ] as $meta_id => $meta_key ) {
[361] Fix | Delete
$meta_key = substr( wp_unslash( $meta_key ), 0, 255 );
[362] Fix | Delete
$meta_value = isset( $items['meta_value'][ $item_id ][ $meta_id ] ) ? wp_unslash( $items['meta_value'][ $item_id ][ $meta_id ] ) : '';
[363] Fix | Delete
[364] Fix | Delete
if ( '' === $meta_key && '' === $meta_value ) {
[365] Fix | Delete
if ( ! strstr( $meta_id, 'new-' ) ) {
[366] Fix | Delete
$item->delete_meta_data_by_mid( $meta_id );
[367] Fix | Delete
}
[368] Fix | Delete
} elseif ( strstr( $meta_id, 'new-' ) ) {
[369] Fix | Delete
$item->add_meta_data( $meta_key, $meta_value, false );
[370] Fix | Delete
} else {
[371] Fix | Delete
$item->update_meta_data( $meta_key, $meta_value, $meta_id );
[372] Fix | Delete
}
[373] Fix | Delete
}
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
// Allow other plugins to change item object before it is saved.
[377] Fix | Delete
/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
[378] Fix | Delete
do_action( 'woocommerce_before_save_order_item', $item );
[379] Fix | Delete
/* phpcs: enable */
[380] Fix | Delete
[381] Fix | Delete
$item->save();
[382] Fix | Delete
[383] Fix | Delete
if ( in_array( $order->get_status(), array( OrderStatus::PROCESSING, OrderStatus::COMPLETED, OrderStatus::ON_HOLD ), true ) ) {
[384] Fix | Delete
$changed_stock = wc_maybe_adjust_line_item_product_stock( $item );
[385] Fix | Delete
if ( $changed_stock && ! is_wp_error( $changed_stock ) ) {
[386] Fix | Delete
$qty_change_order_notes[] = $item->get_name() . ' (' . $changed_stock['from'] . '&rarr;' . $changed_stock['to'] . ')';
[387] Fix | Delete
}
[388] Fix | Delete
}
[389] Fix | Delete
}
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
// Shipping Rows.
[393] Fix | Delete
if ( isset( $items['shipping_method_id'] ) ) {
[394] Fix | Delete
$data_keys = array(
[395] Fix | Delete
'shipping_method' => null,
[396] Fix | Delete
'shipping_method_title' => null,
[397] Fix | Delete
'shipping_cost' => 0,
[398] Fix | Delete
'shipping_taxes' => array(),
[399] Fix | Delete
);
[400] Fix | Delete
[401] Fix | Delete
foreach ( $items['shipping_method_id'] as $item_id ) {
[402] Fix | Delete
$item = WC_Order_Factory::get_order_item( absint( $item_id ) );
[403] Fix | Delete
[404] Fix | Delete
if ( ! $item ) {
[405] Fix | Delete
continue;
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
$item_data = array();
[409] Fix | Delete
[410] Fix | Delete
foreach ( $data_keys as $key => $default ) {
[411] Fix | Delete
$item_data[ $key ] = isset( $items[ $key ][ $item_id ] ) ? wc_clean( wp_unslash( $items[ $key ][ $item_id ] ) ) : $default;
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
$item->set_props(
[415] Fix | Delete
array(
[416] Fix | Delete
'method_id' => $item_data['shipping_method'],
[417] Fix | Delete
'method_title' => $item_data['shipping_method_title'],
[418] Fix | Delete
'total' => $item_data['shipping_cost'],
[419] Fix | Delete
'taxes' => array(
[420] Fix | Delete
'total' => $item_data['shipping_taxes'],
[421] Fix | Delete
),
[422] Fix | Delete
)
[423] Fix | Delete
);
[424] Fix | Delete
[425] Fix | Delete
if ( isset( $items['meta_key'][ $item_id ], $items['meta_value'][ $item_id ] ) ) {
[426] Fix | Delete
foreach ( $items['meta_key'][ $item_id ] as $meta_id => $meta_key ) {
[427] Fix | Delete
$meta_value = isset( $items['meta_value'][ $item_id ][ $meta_id ] ) ? wp_unslash( $items['meta_value'][ $item_id ][ $meta_id ] ) : '';
[428] Fix | Delete
[429] Fix | Delete
if ( '' === $meta_key && '' === $meta_value ) {
[430] Fix | Delete
if ( ! strstr( $meta_id, 'new-' ) ) {
[431] Fix | Delete
$item->delete_meta_data_by_mid( $meta_id );
[432] Fix | Delete
}
[433] Fix | Delete
} elseif ( strstr( $meta_id, 'new-' ) ) {
[434] Fix | Delete
$item->add_meta_data( $meta_key, $meta_value, false );
[435] Fix | Delete
} else {
[436] Fix | Delete
$item->update_meta_data( $meta_key, $meta_value, $meta_id );
[437] Fix | Delete
}
[438] Fix | Delete
}
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
$item->save();
[442] Fix | Delete
}
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
$order = wc_get_order( $order_id );
[446] Fix | Delete
[447] Fix | Delete
if ( ! empty( $qty_change_order_notes ) ) {
[448] Fix | Delete
/* translators: %s item name. */
[449] Fix | Delete
$order->add_order_note( sprintf( __( 'Adjusted stock: %s', 'woocommerce' ), implode( ', ', $qty_change_order_notes ) ), false, true );
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
$order->update_taxes();
[453] Fix | Delete
[454] Fix | Delete
// Only recalculate when a coupon is applied.
[455] Fix | Delete
// This allows manual discounts to be preserved when order items are saved.
[456] Fix | Delete
$order_coupons = $order->get_coupons();
[457] Fix | Delete
if ( ! empty( $order_coupons ) ) {
[458] Fix | Delete
$order->recalculate_coupons();
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
$order->calculate_totals( false );
[462] Fix | Delete
[463] Fix | Delete
// Inform other plugins that the items have been saved.
[464] Fix | Delete
/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
[465] Fix | Delete
do_action( 'woocommerce_saved_order_items', $order_id, $items );
[466] Fix | Delete
/* phpcs: enable */
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
/**
[470] Fix | Delete
* Get HTML for some action buttons. Used in list tables.
[471] Fix | Delete
*
[472] Fix | Delete
* @since 3.3.0
[473] Fix | Delete
* @param array $actions Actions to output.
[474] Fix | Delete
* @return string
[475] Fix | Delete
*/
[476] Fix | Delete
function wc_render_action_buttons( $actions ) {
[477] Fix | Delete
$actions_html = '';
[478] Fix | Delete
[479] Fix | Delete
foreach ( $actions as $action ) {
[480] Fix | Delete
if ( isset( $action['group'] ) ) {
[481] Fix | Delete
$actions_html .= '<div class="wc-action-button-group"><label>' . $action['group'] . '</label> <span class="wc-action-button-group__items">' . wc_render_action_buttons( $action['actions'] ) . '</span></div>';
[482] Fix | Delete
} elseif ( isset( $action['action'], $action['url'], $action['name'] ) ) {
[483] Fix | Delete
$actions_html .= sprintf( '<a class="button wc-action-button wc-action-button-%1$s %1$s" href="%2$s" aria-label="%3$s" title="%3$s">%4$s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( isset( $action['title'] ) ? $action['title'] : $action['name'] ), esc_html( $action['name'] ) );
[484] Fix | Delete
}
[485] Fix | Delete
}
[486] Fix | Delete
[487] Fix | Delete
return $actions_html;
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
/**
[491] Fix | Delete
* Shows a notice if variations are missing prices.
[492] Fix | Delete
*
[493] Fix | Delete
* @since 3.6.0
[494] Fix | Delete
* @param WC_Product $product_object Product object.
[495] Fix | Delete
*/
[496] Fix | Delete
function wc_render_invalid_variation_notice( $product_object ) {
[497] Fix | Delete
global $wpdb;
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function