Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
  2. add_action('woocommerce_before_single_product', 'check_if_variable_first');
  3.  
  4. function check_if_variable_first()
  5. {
  6. if (is_product()) {
  7. global $post;
  8. $product = wc_get_product($post->ID);
  9. if ($product->is_type('variable')) {
  10. // removing the price of variable products
  11. // Change location of
  12. add_action('woocommerce_single_product_summary', 'custom_wc_template_single_price', 20);
  13. function custom_wc_template_single_price()
  14. {
  15. global $product;
  16. // Variable product only
  17. if ($product->is_type('variable')):
  18. // Main Price
  19.  
  20. $prices = array($product->get_variation_price('min', true), $product->get_variation_price('max', true));
  21. $price = $prices[0] !== $prices[1] ? sprintf(__('od %1$s <small>s DPH</small>', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]);
  22.  
  23. // Sale Price
  24. $prices = array($product->get_variation_regular_price('min', true), $product->get_variation_regular_price('max', true));
  25. sort($prices);
  26. $saleprice = $prices[0] !== $prices[1] ? sprintf(__('od %1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]);
  27.  
  28. if ($price !== $saleprice && $product->is_on_sale()) {
  29. $price = '<del>' . $saleprice . $product->get_price_suffix() . '</del> <ins>' . $price . $product->get_price_suffix() . '</ins>';
  30. }
  31. ?>
  32. <style>
  33. div.woocommerce-variation-price,
  34. div.woocommerce-variation-availability,
  35. div.hidden-variable-price {
  36. height: 0px !important;
  37. overflow: hidden;
  38. position: relative;
  39. line-height: 0px !important;
  40. font-size: 0% !important;
  41. }
  42. </style>
  43.  
  44. <script>
  45. jQuery(document).ready(function ($) {
  46. $('select').blur(function () {
  47. if ('' != $('input.variation_id').val()) {
  48. $('p.price').html($('div.woocommerce-variation-price > span.price').html()).append('<p class="availability">' + $('div.woocommerce-variation-availability').html() + '</p>');
  49. console.log($('input.variation_id').val());
  50. } else {
  51. $('p.price').html($('div.hidden-variable-price').html());
  52. if ($('p.availability'))
  53. $('p.availability').remove();
  54. console.log('NULL');
  55. }
  56. });
  57. });
  58. </script>
  59. <?php
  60. echo '<p class="price">' . $price . '</p><div class="hidden-variable-price" >' . $price . '</div>';
  61. endif;
  62. }
  63. }
  64. }
  65. }
  66.  
  67. <?php
  68. function iconic_variable_price_format( $price, $product ) {
  69.  
  70. $prefix = sprintf('%s ', __('Od', 'iconic'));
  71.  
  72. $min_price_regular = $product->get_variation_regular_price( 'min', true );
  73. $min_price_sale = $product->get_variation_sale_price( 'min', true );
  74. $max_price = $product->get_variation_price( 'max', true );
  75. $min_price = $product->get_variation_price( 'min', true );
  76.  
  77. $price = ( $min_price_sale == $min_price_regular ) ?
  78. wc_price( $min_price_regular ) :
  79. '<del>' . wc_price( $min_price_regular ) . '</del>' . '<ins>' . wc_price( $min_price_sale ) . '</ins>';
  80.  
  81. return ( $min_price == $max_price ) ?
  82. $price :
  83. sprintf('%s%s', $prefix, $price);
  84.  
  85. }
  86. add_filter( 'woocommerce_variable_sale_price_html','iconic_variable_price_format', 10, 2 );
  87. add_filter( 'woocommerce_variable_price_html', 'iconic_variable_price_format', 10, 2 );?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement