How to make a script work only once for one product?
4 USDadd_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 ); function woocommerce_total_product_price() { global $woocommerce, $product; // let's setup our divs echo sprintf('%s %s',__('Product Total:','woocommerce'),' $'.$product->get_price().'For one unit.'); // echo sprintf('%s %s',__('Cart Total:','woocommerce'),' $'.$product->get_price().“ )?> jQuery(document).ready(function($){ // grab the price var initial_price = $('[itemprop="price"]').attr('content'); $('.qty').on('change',function(){ var total_price = initial_price * this.value; console.log(initial_price, this.value, total_price); }); }) jQuery(function($){ var price = , current_cart_total = , currency = ''; $('[name=quantity]').change(function(){ if (!The Value1) { var product_total = parseFloat(price * this.value), cart_total = parseFloat(product_total + current_cart_total); $('#product_total_price .price').html( currency + product_total.toFixed(2)); $('#cart_total_price .price').html( currency + cart_total.toFixed(2)); } $('#product_total_price,#cart_total_price').toggle(!The Value
Сайт на Wordpress. Использую Woocommerce. У меня в functions.php находиться вот такой код:
add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 ); function woocommerce_total_product_price() { global $woocommerce, $product; // let's setup our divs echo sprintf('<div id="product_total_price" style="font-size: 18px;color: #ff0e0e;margin-bottom:20px;">%s %s</div>',__('Product Total:','woocommerce'),'<span style="color: #ff0e0e;" class="price"> $'.$product->get_price().' - for one unit!</span>'); // echo sprintf('<div id="cart_total_price" style="margin-bottom:20px;">%s %s</div>',__('Cart Total:','woocommerce'),'<span class="price"> $'.$product->get_price().'</span>'); ?> <script> jQuery(document).ready(function($){ // grab the price var initial_price = $('[itemprop="price"]').attr('content'); $('.qty').on('change',function(){ var total_price = initial_price * this.value; console.log(initial_price, this.value, total_price); }); }) jQuery(function($){ var price = <?php echo $product->get_price(); ?>, current_cart_total = <?php echo $woocommerce->cart->cart_contents_total; ?>, currency = '<?php echo get_woocommerce_currency_symbol(); ?>'; $('[name=quantity]').change(function(){ if (!(this.value < 1)) { var product_total = parseFloat(price * this.value), cart_total = parseFloat(product_total + current_cart_total); $('#product_total_price .price').html( currency + product_total.toFixed(2)); $('#cart_total_price .price').html( currency + cart_total.toFixed(2)); } $('#product_total_price,#cart_total_price').toggle(!(this.value <= 1)); }); }); </script> <?php }
Он отвечает за вывод общей суммы цены (при выборе количества) товаров. Он отлично работает, когда на странице находиться один товар. Но когда их два, то при смене количества на одном, на втором показывается цена первого. Как остановить скрипт в рамках одного товара?
Client's feedback on cooperation with Sergey B.
How to make a script work only once for one product?It’s perfect 10-10!
Freelancer's feedback on cooperation with Misha Osadchuk
How to make a script work only once for one product?Well arranged TZ. It was nice to work.
-
1514 167 0 1 Good day . Ready to fulfill your task. Show the site where this code works.
Добрый день. Готов взяться за выполнение Вашего задания. Покажите сайт где работает этот код
-
Это Вы типа хотите просто рекомендаций?
-
Нет, за оплату решить проблему, цена договорная.
-
Да просто посидите и поройтесь в инете и попробуйте сами привязать ваш скрипт к id товара.
Это и деньги вам сохранит и скилл увеличит
-
Current freelance projects in the category JavaScript
Write an extension for Google Chrome
22 USD
Extension is needed for Google Chrome (fake forecast of the next number or color for the casino) Need to remember the last entered numbers and when the button is pressed, a random number is displayed Also need to remember the entered color and when the button is pressed, show a… JavaScript, Web programming ∙ 3 proposals |
Fix the landing page for Google Ads, clean up compromised linksSpecialist needed to clean compromised links from the website https://armadom.com.ua/ (landing was done on webflow) Google support writes: clean compromised links added below: cdnmetric[.]com/ Write if you have experience with this and know how to fix it to pass the appeal in… JavaScript, Web programming |
Laravel + VueJS + InertiaJSGood day, the project is written, it is working and ready to launch. Except for one nuance. SSR(Server Side Rendering) works very slowly, when launching a bot to check the load - the site crashes after 3-4 minutes. If you restart SSR during the check, it works but very slowly.… JavaScript, PHP ∙ 2 proposals |
Writing software for creating an Open Book on the Solana network
107 USD
During the creation of interchangeable tokens (SPL token) on the Solana network, it is necessary to automate the process of creating an Open Book for the token and speed it up by increasing transaction fees. Software functions: - Create Open Book - Set a "tea" limit on the… Java, JavaScript |
Website layout according to the design.
510 USD
Good day. There is a layout in Figma: https://www.figma.com/file/RGVIymprYc4QaiJ5qp3iwL/LayerGame?type=design&node-id=0-1&mode=design There is a UI kit and a ready-made layout of the Main page, implemented in React, animations are done using GSAP. It is necessary to layout 2… HTML and CSS, JavaScript ∙ 38 proposals |