Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Sark

    (@sarkware)

    The plugin doesn’t support that feature, but it is easy to implement.
    Just share your product page url, based on the number field I will give write a php snippet which can be placed on your functions.php file.

    Thread Starter droptozero

    (@droptozero)

    Thanks for your reply Sark.

    Here’s the product page. https://2xl.dba.myftpupload.com/product/physical-eviction/ the fields under eviction fees needs the multiply function. thank you

    Plugin Contributor Sark

    (@sarkware)

    Put the following snippet on your functions.php, pls take the backup before updating.
    and have the FTP access ready, incase we managed to brick the site.

    add_filter('woocommerce_add_cart_item', 'handle_custom_pricing', 999, 2);
    add_filter('woocommerce_get_cart_item_from_session', 'handle_custom_pricing', 999, 2);
    
    function handle_custom_pricing($citem, $cart_item_key) {
    
    	$movers = 70;
    	$sadmin = 145;
    	$locksmith = 135;
    	$drilllock = 90;
    	$trashbag = 35;
    	$truck = 175;
    	$photo = 100;
    	$moverbox = 6;
    	$lockbox = 65;
    	$installlock = 50;
    	$carpenter = 195;
    
    	$addonPrice = 0;
    	$orgPrice = method_exists($citem["data"], "get_price") ? floatval ($citem['data']->get_price()) : floatval ($citem['data']->price);
    
    	foreach ($citem as $ckey => $cval) {
    		if ((strpos($ckey, "wccpf_") !== false)) {
    
    			/* Movers */
    			if ($ckey == "wccpf_cFpG0qlhqYeh" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $movers);
    				}				
    			}
    
    			/* Store Admin */
    			if ($ckey == "wccpf_0eqnwd6oZ82m" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $sadmin);
    				}				
    			}
    
    			/* Locksmith */
    			if ($ckey == "wccpf_EV1CUaxabkEO" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $locksmith);
    				}				
    			}
    
    			/* Drill off Lock */
    			if ($ckey == "wccpf_GSWzymvZGhrN" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $drilllock);
    				}				
    			}
    
    			/* Trash bag */
    			if ($ckey == "wccpf_kBvy2naZ321P" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $trashbag);
    				}				
    			}
    
    			/* Truck */
    			if ($ckey == "wccpf_YkLLoD8kyJl6" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $truck);
    				}				
    			}
    			
    			/* Property Photo */
    			if ($ckey == "wccpf_qVXRjo0pY4E6" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $photo);
    				}				
    			}
    
    			/* Mover Box */
    			if ($ckey == "wccpf_cnJAumM5wyhO" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $moverbox);
    				}				
    			}
    
    			/* Lock Box */
    			if ($ckey == "wccpf_lL44sbHGX72s" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $lockbox);
    				}				
    			}
    
    			/* Install New Lock */
    			if ($ckey == "wccpf_Pc1kiXfZfI2z" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $installlock);
    				}				
    			}
    
    			/* Carpenter */
    			if ($ckey == "wccpf_A85EOjETBLtT" && isset($citem [$ckey]["user_val"])) {
    				$uval = abs($citem [$ckey]["user_val"]);
    				if (is_numeric($uval)) {
    					$addonPrice += ($uval * $carpenter);
    				}				
    			}
    		}
    	}
    
    	$orgPrice = $orgPrice + $addonPrice;
    
    	/* Update the price */
    	if (method_exists ($citem ["data"], "set_price")) {
    		/* Woocommerce 3.0.6 + */
    		$citem["data"]->set_price($orgPrice);
    	} else {
    		/* Woocommerece before 3.0.6 */
    		$citem["data"]->price = $orgPrice;
    	}
    
    	return $citem;
    
    }
    Thread Starter droptozero

    (@droptozero)

    Thank you sark, i really appreciate your help.
    however there was an error. please check screenshots.

    View post on imgur.com

    View post on imgur.com

    Plugin Contributor Sark

    (@sarkware)

    Hi, it was updated, especially the two add_filter.

    Pls update and let me know how it goes.

    Thread Starter droptozero

    (@droptozero)

    Hi sark. thanks for your help. it is working now.

    Plugin Contributor Sark

    (@sarkware)

    Glad to hear, you can also write some JS snippet to update the price in the client side itself.

    Also your product page looks cool, I thought no one using the Custom Layout option.
    Despite the lack of documentation, you managed to use that option to built your product page.

    Thread Starter droptozero

    (@droptozero)

    Hey Sark, Thank you. if you can guide me for the javascript to update the price on the client side i will much appreciate it.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Pricing Rule Multiply’ is closed to new replies.