Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'gform_product_info', function( $product_info, $form, $entry ) {
- // 6 is the qty field ID of the form you need to change it with your form qty id
- if ( rgar( $entry, 6 ) > 2 ) {
- $total = get_total($product_info);
- $fee = ($total * 0.6);
- $product_info = array(
- 'products' => array(
- array(
- 'name' => 'Discounted',
- 'price' => $fee,
- 'quantity' => 1,
- ),
- ),
- );
- } else if ( rgar( $entry, 6 ) > 1 ) {
- $total = get_total($product_info);
- $fee2 = ($total * 0.7);
- $product_info = array(
- 'products' => array(
- array(
- 'name' => 'Discounted',
- 'price' => $fee2,
- 'quantity' => 1,
- ),
- ),
- );
- }
- return $product_info;
- }, 10, 3 );
- function get_total($products) {
- $total = 0;
- foreach($products["products"] as $product){
- $price = GFCommon::to_number($product["price"]);
- if(isset($product["options"]) && is_array($product["options"])){
- foreach($product["options"] as $option){
- $price += GFCommon::to_number($option["price"]);
- }
- }
- $subtotal = floatval($product["quantity"]) * $price;
- $total += $subtotal;
- }
- $total += floatval($products["shipping"]["price"]);
- return $total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement