Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_before_shipping_calculator', 'add_custom_price'
- );
- function add_custom_price( $cart_object ) {
- foreach ( $cart_object->cart_contents as $key => $value ) {
- $value['data']->price = 400;
- }
- }
- add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 20, 1);
- function add_custom_price( $cart_obj ) {
- // This is necessary for WC 3.0+
- if ( is_admin() && ! defined( 'DOING_AJAX' ) )
- return;
- // Avoiding hook repetition (when using price calculations for example)
- if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
- return;
- // Loop through cart items
- foreach ( $cart_obj->get_cart() as $cart_item ) {
- $cart_item['data']->set_price( 40 );
- }
- }
Add Comment
Please, Sign In to add comment