Guest User

Untitled

a guest
Sep 30th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. add_action( 'woocommerce_before_shipping_calculator', 'add_custom_price'
  2. );
  3. function add_custom_price( $cart_object ) {
  4. foreach ( $cart_object->cart_contents as $key => $value ) {
  5. $value['data']->price = 400;
  6. }
  7. }
  8.  
  9. add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 20, 1);
  10. function add_custom_price( $cart_obj ) {
  11.  
  12. // This is necessary for WC 3.0+
  13. if ( is_admin() && ! defined( 'DOING_AJAX' ) )
  14. return;
  15.  
  16. // Avoiding hook repetition (when using price calculations for example)
  17. if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
  18. return;
  19.  
  20. // Loop through cart items
  21. foreach ( $cart_obj->get_cart() as $cart_item ) {
  22. $cart_item['data']->set_price( 40 );
  23. }
  24. }
Add Comment
Please, Sign In to add comment