Я пытаюсь создать плагин WooCommerce для страниц отдельных товаров. Мне нужно сложить обычные цены с индивидуальными ценами. Мне удалось получить сумму обычной цены и индивидуальной цены, но когда я нажимаю «Добавить в корзину», я не могу установить новую расчетную цену в корзине.
Любая помощь приветствуется.
Я пытаюсь создать плагин WooCommerce для страниц отдельных товаров. Мне нужно сложить обычные цены с индивидуальными ценами. Мне удалось получить сумму обычной цены и индивидуальной цены, но когда я нажимаю «Добавить в корзину», я не могу установить новую расчетную цену в корзине. Любая помощь приветствуется. [code]// WooCommerce activation function custom_product_page() { global $wpdb; global $product; wp_enqueue_style('my-plugin-styles', plugins_url('assets/css/diamond_style.css', __FILE__));
if (class_exists('WooCommerce') && is_product()) { $product = wc_get_product(get_the_ID());
// Show Metal Color only if the product category is "ring" if ($is_ring) { // Retrieve the latest gold rate $gold_rate_table = $wpdb->prefix . 'gold_rate'; $gold_rate = $wpdb->get_var("SELECT final_price FROM $gold_rate_table ORDER BY id DESC LIMIT 1");
// Get the net weight attribute $net_weight = $product->get_attribute('net-weight-g');
// Get the regular price $regular_price = $product->get_regular_price();
// Update cart item price with the custom price add_filter('woocommerce_add_cart_item', function ($cart_item) use ($updated_price) { $cart_item['data']->set_price($updated_price); return $cart_item; }); } } } add_action('woocommerce_single_product_summary', 'custom_product_page', 25); [/code] Я пробовал использовать add_filter, но мне не помогло.