function wc_autoship_initial_price_insert($table_name, $data, $result, $id) { global $wpdb; if ($result === false || empty($id)) { return; } if ($table_name != "{$wpdb->prefix}wc_autoship_schedule_items") { return; } // Get item if (!WC_Autoship_Schedule_Item::id_exists($id)) { return; } $item = new WC_Autoship_Schedule_Item($id); // Get price $product_id = $item->get_product_id(); $variation_id = $item->get_variation_id(); $price_product_id = empty($variation_id) ? $product_id : $variation_id; $autoship_price = get_post_meta($price_product_id, '_wc_autoship_price', true); if (empty($autoship_price)) { return; } // Insert price $wpdb->query($wpdb->prepare("INSERT IGNORE INTO {$wpdb->prefix}wc_autoship_initial_prices(schedule_item_id, price, created_time, modified_time)\n\t\t\tVALUES(%d, %f, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)", $id, $autoship_price)); }