Ecommerce Shopify WordPress Discussion

Issue with Saving Options from First Request in PHP wodpress

I have encountered an issue in my PHP code where it is not saving the option from the first request but instead saving it from the second request. I am using the following code: // Add ajax action for authenticated users add_action( "wp_ajax_SavingProductTitleArray", "SavingProductTitleArray" ); // Add ajax action for non-authenticated users add_action( "wp_ajax_nopriv_SavingProductTitleArray", "SavingProductTitleArray" ); // Function to handle saving product title array function SavingProductTitleArray(){ // Creating an instance of MyCoreProducts class $data = new MyCoreProducts(); // Check if 'scan' variable is set to 1 in POST data if (isset($_POST['scan']) && $_POST['scan'] == 1) { // Get the existing product title array from plugin options global $my_plugin_opts; $old_products = $my_plugin_opts['my_plugin_option_product']; // Get the new product title array from MyCoreProducts class method $new_data = $data->getProductsTitleArray(); // If no existing product array is found, create a new one if (empty($old_products) || !isset($old_products)) { // Check if 'myplugin_opts' option exists if (get_option('myplugin_opts') !== false) { // Get existing plugin options $my_plugin_option = get_option('myplugin_opts'); // Update the product title array in the options $my_plugin_option['my_plugin_option_product'] = $new_data; update_option('myplugin_opts', $my_plugin_option); } } } } I am expecting the option to be saved from the first request, but it seems like it is not working as intended. I have tried debugging the code and checking the values of $old_products and $new_data, but I have not been able to identify the issue. I would greatly appreciate any insights or suggestions on how to resolve this issue and ensure that the option is saved from the first request. Thank you in advance for your help.)
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.