C
C
castetus2020-05-06 01:09:51
WordPress
castetus, 2020-05-06 01:09:51

Why is product metadata not saved?

Hello everyone!
I want to massively change product descriptions, but the result of the update_post_meta execution is not written to the database.
What's wrong?

add_action('admin_init', 'replace_products');
function replace_products(){
      $prod = wc_get_product('2425274161');
      $id = $prod->get_id();
      $description = $prod->get_description('edit');
      $search_string = 'Субпродукты и рубец';
      $new_description = str_replace($search_string, 'рубец', $description);
      update_post_meta($id, 'description', $new_description, $description);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
castetus, 2020-05-06
@castetus

In short, it works if done not through update_post_meta but through $product->set_description();
I feel like I'll never understand how Wookomers posts work :(

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question