Advertisement
thesufi

Override Woo Product Price

Sep 1st, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. /*
  2.  * make all products price to zero
  3.  */
  4. add_filter('woocommerce_product_get_price', 'dctit_set_products_price_to_zero', 99, 2 );
  5. add_filter('woocommerce_product_get_regular_price', 'dctit_set_products_price_to_zero', 99, 2 );
  6. add_filter('woocommerce_product_get_sale_price', 'dctit_set_products_price_to_zero', 99, 2 );
  7. // Variations
  8. add_filter('woocommerce_product_variation_get_regular_price', 'dctit_set_products_price_to_zero', 99, 2 );
  9. add_filter('woocommerce_product_variation_get_price', 'dctit_set_products_price_to_zero', 99, 2 );
  10. add_filter('woocommerce_product_variation_get_sale_price', 'dctit_set_products_price_to_zero', 99, 2 );
  11. function dctit_set_products_price_to_zero ( $price, $product ) {
  12.     //remove cached prices
  13.     //wc_delete_product_transients( $product->get_id() );
  14.    
  15.     $price = 0;
  16.     return $price;
  17. }
  18.  
  19. //variable products
  20. add_filter('woocommerce_variation_prices_price', 'dctit_set_variable_products_price_to_zero', 99, 3 );
  21. add_filter('woocommerce_variation_prices_regular_price', 'dctit_set_variable_products_price_to_zero', 99, 3 );
  22. add_filter('woocommerce_variation_prices_sale_price', 'dctit_set_variable_products_price_to_zero', 99, 3 );
  23. function dctit_set_variable_products_price_to_zero ( $price, $variation, $product ) {
  24.     //remove cached prices
  25.     //wc_delete_product_transients( $product->get_id() );
  26.    
  27.     $price = 0;
  28.     return $price;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement