rpress_proceed_checkout

Author: RestroPress 19 views

Filter used to validate and modify the data while proceeding to the checkout page . It contain one parameter $responce ,witch contain the data of the cart.

The sample below shows an example of how you could modify it:

 function rpress_delivery_fee_validate_purchase( $response ) {

   $service_type = isset( $_COOKIE['service_type'] ) ? $_COOKIE['service_type'] : 'pickup';

   if ( $service_type == 'pickup' ) {

     RPRESS()->fees->remove_fee( 'delivery_fee' );

     return $response;

   }

   $delivery_settings = RP_Delivery_Fee_Settings::rp_fee_settings();

   $minimum_order_amount_error = isset( $delivery_settings['minimum_order_amount_error'] ) ? $delivery_settings['minimum_order_amount_error'] : __('Minimum order amount for this address is ') . '{minimum_order_amount}';

   $delivery_zip_code = isset( $_COOKIE['delivery_zip'] ) ? $_COOKIE['delivery_zip'] : '';

   $delivery_latlng = isset( $_COOKIE['delivery_latlng'] ) ? ( trim( $_COOKIE['delivery_latlng'] ) ) : '';

   $store_position = isset( $_COOKIE['store_lat_long'] ) ? $_COOKIE['store_lat_long'] : '';

   $delivery_location = isset( $_COOKIE['delivery_location'] ) ? ( trim( $_COOKIE['delivery_location'] ) ) : '';

   $delivery_fee_method = isset( $delivery_settings['delivery_method'] ) ?   $delivery_settings['delivery_method'] : 'zip_based';

   $cart_subtotal = rpress_get_cart_subtotal();

   $tax = rpress_get_cart_tax();

   $new_cart_subtotal = $cart_subtotal + $tax;

   if ( $delivery_fee_method == 'zip_based' ) {

     if ( !empty( $delivery_zip_code ) ) {
         $delivery_response = $this->get_delivery_fee_by_zip( $delivery_zip_code );
    }
  } else {
       if ( !empty( $delivery_latlng ) ) {

          $delivery_response = $this->get_delivery_fee_by_location( $delivery_latlng, $store_position );

      }

   }

  $set_min_order_amount = isset( $delivery_response['set_min_order_amount'] ) ? $delivery_response['set_min_order_amount'] : 0;

  if ( $set_min_order_amount != 0 && $set_min_order_amount > 0 && $new_cart_subtotal < $set_min_order_amount ) {

    $min_order_amount_message = str_replace( '{minimum_order_amount}', rpress_currency_filter( rpress_format_amount( $set_min_order_amount ) ) , $minimum_order_amount_error );
    $response['status'] = 'error';
    $response['error_msg'] = $response['msg'] = $min_order_amount_message;

 }

 return $response;
}

add_filter( 'rpress_proceed_checkout', 'rpress_delivery_fee_validate_purchase', 10, 1 );