ID, '_aksrt_price', true); $stock = (int) get_post_meta($post->ID, '_aksrt_stock', true); $image = (string) get_post_meta($post->ID, '_aksrt_product_image', true); $gallery = get_post_meta($post->ID, '_aksrt_product_gallery', true); $gallery = is_array($gallery) ? $gallery : []; $shipping_mode = (string) get_post_meta($post->ID, '_aksrt_shipping_mode', true); $shipping_fee = (float) get_post_meta($post->ID, '_aksrt_shipping_fee', true); $after_sale_policy = (string) get_post_meta($post->ID, '_aksrt_after_sale_policy', true); $support_refund = get_post_meta($post->ID, '_aksrt_support_refund', true); $support_refund = $support_refund === '' ? '1' : (string) $support_refund; $limit_buy = get_post_meta($post->ID, '_aksrt_limit_buy', true); $limit_buy = $limit_buy === '' ? -1 : (int) $limit_buy; $stock_type = (string) (get_post_meta($post->ID, '_aksrt_stock_type', true) ?: 'all'); $pay_modo = (string) (get_post_meta($post->ID, '_aksrt_pay_modo', true) ?: '0'); $start_price = (float) get_post_meta($post->ID, '_aksrt_start_price', true); $delivery_note = (string) get_post_meta($post->ID, '_aksrt_delivery_note', true); $marketing = (string) get_post_meta($post->ID, '_aksrt_marketing_headline', true); $shipping_modes = [ '' => __('默认(继承设置)', 'aksrt'), 'express' => __('快递物流', 'aksrt'), 'auto' => __('自动发货', 'aksrt'), 'manual' => __('手动发货', 'aksrt'), 'virtual' => __('虚拟商品', 'aksrt'), ]; $stock_types = [ 'all' => __('统一库存', 'aksrt'), 'opts' => __('按选项/变体', 'aksrt'), ]; ?>

post_type !== 'aksrt_product') { return; } if (!current_user_can('edit_post', $post_id)) { return; } $price = isset($_POST['aksrt_price']) ? max(0, (float) wp_unslash($_POST['aksrt_price'])) : 0; $stock = isset($_POST['aksrt_stock']) ? (int) wp_unslash($_POST['aksrt_stock']) : 0; if ($stock < -1) { $stock = -1; } $image = isset($_POST['aksrt_product_image']) ? esc_url_raw((string) wp_unslash($_POST['aksrt_product_image'])) : ''; $gallery_raw = isset($_POST['aksrt_product_gallery']) ? (string) wp_unslash($_POST['aksrt_product_gallery']) : ''; $gallery = array_values(array_filter(array_map( static function ($line) { return esc_url_raw(trim((string) $line)); }, preg_split('/\r\n|\r|\n/', $gallery_raw) ?: [] ))); $shipping_mode = isset($_POST['aksrt_shipping_mode']) ? sanitize_key((string) wp_unslash($_POST['aksrt_shipping_mode'])) : ''; $shipping_fee = isset($_POST['aksrt_shipping_fee']) ? max(0, (float) wp_unslash($_POST['aksrt_shipping_fee'])) : 0; $policy = isset($_POST['aksrt_after_sale_policy']) ? sanitize_textarea_field((string) wp_unslash($_POST['aksrt_after_sale_policy'])) : ''; $support_refund = !empty($_POST['aksrt_support_refund']) ? '1' : '0'; $limit_buy = isset($_POST['aksrt_limit_buy']) ? max(-1, min(9999, (int) wp_unslash($_POST['aksrt_limit_buy']))) : -1; $stock_type = isset($_POST['aksrt_stock_type']) ? sanitize_key((string) wp_unslash($_POST['aksrt_stock_type'])) : 'all'; if (!in_array($stock_type, ['all', 'opts'], true)) { $stock_type = 'all'; } $pay_modo = isset($_POST['aksrt_pay_modo']) ? sanitize_key((string) wp_unslash($_POST['aksrt_pay_modo'])) : '0'; if (!in_array($pay_modo, ['0', 'points'], true)) { $pay_modo = '0'; } $start_price = isset($_POST['aksrt_start_price']) ? max(0, (float) wp_unslash($_POST['aksrt_start_price'])) : 0; $delivery_note = isset($_POST['aksrt_delivery_note']) ? sanitize_text_field((string) wp_unslash($_POST['aksrt_delivery_note'])) : ''; $marketing = isset($_POST['aksrt_marketing_headline']) ? sanitize_text_field((string) wp_unslash($_POST['aksrt_marketing_headline'])) : ''; update_post_meta($post_id, '_aksrt_price', $price); update_post_meta($post_id, '_aksrt_stock', $stock); update_post_meta($post_id, '_aksrt_product_image', $image); update_post_meta($post_id, '_aksrt_product_gallery', $gallery); update_post_meta($post_id, '_aksrt_shipping_mode', $shipping_mode); update_post_meta($post_id, '_aksrt_shipping_type', $shipping_mode); update_post_meta($post_id, '_aksrt_shipping_fee', $shipping_fee); update_post_meta($post_id, '_aksrt_after_sale_policy', $policy); update_post_meta($post_id, '_aksrt_support_refund', $support_refund); update_post_meta($post_id, '_aksrt_limit_buy', $limit_buy); update_post_meta($post_id, '_aksrt_stock_type', $stock_type); update_post_meta($post_id, '_aksrt_pay_modo', $pay_modo); update_post_meta($post_id, '_aksrt_start_price', $start_price); update_post_meta($post_id, '_aksrt_delivery_note', $delivery_note); update_post_meta($post_id, '_aksrt_marketing_headline', $marketing); // Keep sales counter present for list columns. if (get_post_meta($post_id, '_aksrt_sales', true) === '') { update_post_meta($post_id, '_aksrt_sales', 0); } } }