TALAWEB - the freelance web geek
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Plugins
In reply to: [WooCommerce] Replace Sale Price with a button to show/hide the valueHere’s my solution:
functions.php
add_filter( 'woocommerce_get_price_html', 'tlw_custom_price', 10, 2 ); function tlw_custom_price() { global $product; $saleprice = $product->get_sale_price(); $fullprice = $saleprice + 200; if ( is_product() ) { if ( $product->is_on_sale() ) { if( $product->is_type('simple') || $product->is_type('external') || $product->is_type('grouped') ) { $regular_price = get_post_meta( $product->get_id(), '_regular_price', true ); $sale_price = get_post_meta( $product->get_id(), '_sale_price', true ); if( !empty($sale_price) ) { print '<p class="price">' . '<div class="regular-price">' . '<h4 class="woocommerce-Price-amount amount">Original price:<br />' . number_format($regular_price, 0, '', ' ') . ' EUR</h4></div>' . '<h5 class="red">Need it cheaper? Click here!</h5>' . '<p><button class="show-price-button button blue" onclick="showPrice()">Get my discount</button></p>' . '<h4 id="hidden-price" class="sale-price">Discount price:<br />' . number_format($sale_price, 0, '', ' ') . ' EUR</h4>' . '</p>'; } } } } }Before </head> tag
<script> function showPrice() { var price = document.getElementById("hidden-price"); if (price.style.display === "block") { price.style.display = "none"; } else { price.style.display = "block"; } } </script>- This reply was modified 4 years, 9 months ago by TALAWEB - the freelance web geek.
Forum: Plugins
In reply to: [WooCommerce] Replace Sale Price with a button to show/hide the valueCustom coding is okay. But how can I modify the price HTML with a function from functions.php file?
Viewing 2 replies - 1 through 2 (of 2 total)