Есть вот такой код:
public static function all_product_atts($post_id): void {
global $wpdb;
$product = wc_get_product($post_id);
$product_attributes = $product->get_attributes();
$product_attributes[] = 'product_cat';
$table_name = $wpdb->prefix . self::$table;
$atts = $type = [];
$product_id = $product->get_id();
if (0 !== count($product_attributes)) {
foreach ($product_attributes as $one_tax) {
$tax = ( $one_tax === 'product_cat' ) ? $one_tax : $one_tax->get_name();
$attribute_values = wc_get_product_terms($product_id, $tax, [ 'fields' => 'all' ]);
$terms_post = '';
foreach ($attribute_values as $attribute_value) {
$terms_post .= '[' . $attribute_value->term_id . ']';
}
$atts[ $tax ] = $terms_post;
$type[] = '%s';
}
}
$price = get_post_meta($product_id, '_regular_price', true);
$atts[ 'price' ] = $price;
$type[] = '%d';
$flag = $wpdb->get_row("SELECT * FROM $table_name WHERE post_id = " . $product_id);
if (!empty($flag)) {
$wpdb->update($table_name, $atts, array( 'post_id' => $product_id ), $type, '%d');
} else {
$atts[ 'post_id' ] = $product_id;
$type[] = '%d';
$wpdb->insert($table_name, $atts, $type);
}
}
Почему при сохранении товара не записывается цена продукта в таблицу БД? Что не так...?