Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

My Hook

Hook

function custom_hook() {
	<?php
	/*
	Plugin Name:	My Hook
	Plugin URI:		https://www.cubixquirrel.com
	Description:	WooCommerce & Toolset Hooks
	Version:		1.0.0
	Author:			Fahad Razi
	Author URI:		https://www.cubixquirrel.com
	License:		GPL-2.0+
	License URI:	http://www.gnu.org/licenses/gpl-2.0.txt
	*/
	
	if ( ! defined( 'WPINC' ) ) {
		die;
	}
	
	/************************** Toolset Form Submit cURL *****************************/
	
	function changenotset($current_options, $title, $type) {
	    foreach ($current_options as &$option) {
	        if ($option['#title']=='--- not set ---') {
	            $option['#title'] = "Select";
	        }
	    }
	    return $current_options;
	}
	add_filter("wpt_field_options", 'changenotset', 10, 3);
	
	/************************** Toolset Form Submit cURL *****************************/
	
	add_action('cred_commerce_form_action', 'my_commerce_form_action',10,4);
	
	function my_commerce_form_action( $action, $form_id, $post_id, $form_data ) {
		
		if ($form_id == 175)
	  {
		$first = urlencode($_POST['wpcf-name']);
	    $mobile = urlencode($_POST['wpcf-mobile-number']);
		$email = urlencode($_POST['wpcf-email-id']);
		$address = urlencode($_POST['wpcf-business-address']);
		$form_name = "GST";
			
		$ch = curl_init('https://www.btpr.online/Capture/Website/Capture.php?License=989810&Name='.$first.'&Contact='.$mobile.'&Email='.$email.'&Website=Sole%20Proprietor&Status=Pending%20Payment&Category=Form&Form%20Name='.$form_name.'');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	
		// execute!
		$response = curl_exec($ch);
	
		// close the connection, release resources used
		curl_close($ch);
	
		// do anything you want with your response
		var_dump($response);
			
		$first2 = $_POST['wpcf-name'];
	    $mobile2 = $_POST['wpcf-mobile-number'];
		$email2 = $_POST['wpcf-email-id'];
	    $address2 = $_POST['wpcf-business-address'];
		$form_name2 = "GST";
			  
		wp_redirect('https://soleproprietor.in/gst-checkout?first='.$first2.'&email='.$email2.'&mobile='.$mobile2.'&address='.$address2.'&customer_note='.$form_name2.'');
		  
		exit();
	  }
		
		if ($form_id == 210)
	  {
		$first = urlencode($_POST['wpcf-name']);
	    $mobile = urlencode($_POST['wpcf-mobile-number']);
		$email = urlencode($_POST['wpcf-email-id']);
		$address = urlencode($_POST['wpcf-business-address']);
		$form_name = "GST";
			
		$ch = curl_init('https://www.btpr.online/Capture/Website/Capture.php?License=989810&Name='.$first.'&Contact='.$mobile.'&Email='.$email.'&Website=Sole%20Proprietor&Status=Pending%20Payment&Category=Form&Form%20Name='.$form_name.'');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	
		// execute!
		$response = curl_exec($ch);
	
		// close the connection, release resources used
		curl_close($ch);
	
		// do anything you want with your response
		var_dump($response);
			
		$first2 = $_POST['wpcf-name'];
	    $mobile2 = $_POST['wpcf-mobile-number'];
		$email2 = $_POST['wpcf-email-id'];
	    $address2 = $_POST['wpcf-business-address'];
		$form_name2 = "GST";
			  
		wp_redirect('https://soleproprietor.in/gst-checkout?first='.$first2.'&email='.$email2.'&mobile='.$mobile2.'&address='.$address2.'&customer_note='.$form_name2.'');
		  
		exit();
	  }
		
		if ($form_id == 216)
	  {
		$first = urlencode($_POST['wpcf-name']);
	    $mobile = urlencode($_POST['wpcf-mobile-number']);
		$email = urlencode($_POST['wpcf-email-id']);
		$address = urlencode($_POST['wpcf-business-address']);
		$form_name = "MSME";
			
		$ch = curl_init('https://www.btpr.online/Capture/Website/Capture.php?License=989810&Name='.$first.'&Contact='.$mobile.'&Email='.$email.'&Website=Sole%20Proprietor&Status=Pending%20Payment&Category=Form&Form%20Name='.$form_name.'');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	
		// execute!
		$response = curl_exec($ch);
	
		// close the connection, release resources used
		curl_close($ch);
	
		// do anything you want with your response
		var_dump($response);
			
		$first2 = $_POST['wpcf-name'];
	    $mobile2 = $_POST['wpcf-mobile-number'];
		$email2 = $_POST['wpcf-email-id'];
	    $address2 = $_POST['wpcf-business-address'];
		$form_name2 = "MSME";
			  
		wp_redirect('https://soleproprietor.in/msme-checkout?first='.$first2.'&email='.$email2.'&mobile='.$mobile2.'&address='.$address2.'&customer_note='.$form_name2.'');
		  
		exit();
	  }
		
		if ($form_id == 224)
	  {
		$first = urlencode($_POST['wpcf-name']);
	    $mobile = urlencode($_POST['wpcf-mobile-number']);
		$email = urlencode($_POST['wpcf-email-id']);
		$address = urlencode($_POST['wpcf-business-address']);
		$form_name = "GST";
			
		$ch = curl_init('https://www.btpr.online/Capture/Website/Capture.php?License=989810&Name='.$first.'&Contact='.$mobile.'&Email='.$email.'&Website=Sole%20Proprietor&Status=Pending%20Payment&Category=Form&Form%20Name='.$form_name.'');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	
		// execute!
		$response = curl_exec($ch);
	
		// close the connection, release resources used
		curl_close($ch);
	
		// do anything you want with your response
		var_dump($response);
			
		$first2 = $_POST['wpcf-name'];
	    $mobile2 = $_POST['wpcf-mobile-number'];
		$email2 = $_POST['wpcf-email-id'];
	    $address2 = $_POST['wpcf-business-address'];
		$form_name2 = "GST";
			  
		wp_redirect('https://soleproprietor.in/gst-checkout?first='.$first2.'&email='.$email2.'&mobile='.$mobile2.'&address='.$address2.'&customer_note='.$form_name2.'');
		  
		exit();
	  }
		
		if ($form_id == 225)
	  {
		$first = urlencode($_POST['wpcf-name']);
	    $mobile = urlencode($_POST['wpcf-mobile-number']);
		$email = urlencode($_POST['wpcf-email-id']);
		$address = urlencode($_POST['wpcf-business-address']);
		$form_name = "MSME";
			
		$ch = curl_init('https://www.btpr.online/Capture/Website/Capture.php?License=989810&Name='.$first.'&Contact='.$mobile.'&Email='.$email.'&Website=Sole%20Proprietor&Status=Pending%20Payment&Category=Form&Form%20Name='.$form_name.'');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	
		// execute!
		$response = curl_exec($ch);
	
		// close the connection, release resources used
		curl_close($ch);
	
		// do anything you want with your response
		var_dump($response);
			
		$first2 = $_POST['wpcf-name'];
	    $mobile2 = $_POST['wpcf-mobile-number'];
		$email2 = $_POST['wpcf-email-id'];
	    $address2 = $_POST['wpcf-business-address'];
		$form_name2 = "MSME";
			  
		wp_redirect('https://soleproprietor.in/msme-checkout?first='.$first2.'&email='.$email2.'&mobile='.$mobile2.'&address='.$address2.'&customer_note='.$form_name2.'');
		  
		exit();
	  }
		
		if ($form_id == 232)
	  {
		$first = urlencode($_POST['wpcf-name']);
	    $mobile = urlencode($_POST['wpcf-mobile-number']);
		$email = urlencode($_POST['wpcf-email-id']);
		$address = urlencode($_POST['wpcf-business-address']);
		$form_name = "GST";
			
		$ch = curl_init('https://www.btpr.online/Capture/Website/Capture.php?License=989810&Name='.$first.'&Contact='.$mobile.'&Email='.$email.'&Website=Sole%20Proprietor&Status=Pending%20Payment&Category=Form&Form%20Name='.$form_name.'');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	
		// execute!
		$response = curl_exec($ch);
	
		// close the connection, release resources used
		curl_close($ch);
	
		// do anything you want with your response
		var_dump($response);
			
		$first2 = $_POST['wpcf-name'];
	    $mobile2 = $_POST['wpcf-mobile-number'];
		$email2 = $_POST['wpcf-email-id'];
	    $address2 = $_POST['wpcf-business-address'];
		$form_name2 = "GST";
			  
		wp_redirect('https://soleproprietor.in/gst-checkout?first='.$first2.'&email='.$email2.'&mobile='.$mobile2.'&address='.$address2.'&customer_note='.$form_name2.'');
		  
		exit();
	  }
	}
	
	/******************************************* Elementor Popup Webhook *******************************************/
	
	// A send custom WebHook
		add_action( 'elementor_pro/forms/new_record', function( $record, $handler ) {
	    //make sure its our form
	    $form_name = $record->get_form_settings( 'form_name' );
	
	    // Replace MY_FORM_NAME with the name you gave your form
	    if ( 'Request Call Back' !== $form_name ) {
	        return;
	    }
	
	    $raw_fields = $record->get( 'fields' );
	    $fields = [];
	    foreach ( $raw_fields as $id => $field ) {
	        $fields[ $id ] = $field['value'];
	    }
		$name = $fields['name'];
		$email = $fields['email'];
		$mobileNumber = $fields['mobile_number'];
		$formName = $fields['formName'];
	
	    // Replace HTTP://YOUR_WEBHOOK_URL with the actuall URL you want to post the form to
	    wp_remote_post( 'https://www.btpr.online/Capture/Website/Capture.php?License=989810&Name='.$name.'&Contact='.$mobileNumber.'&Email='.$email.'&Website=Sole%20Proprietor&Status=Request%20For%20Call%20Back&Category=Enquiry%20Form&Form%20Name='.$formName.'', [
	        'body' => $fields,
	    ]);
	}, 10, 2 );
	
	/************************** Woocommerce Field Required *****************************/
	
	add_filter( 'woocommerce_checkout_fields' , 'fahad_checkout_field_defaults', 20 );
	
	function fahad_checkout_field_defaults( $fields ) {
	    $first_name = isset($_GET['first']) ? $_GET['first'] : '';
		$mobile_no = isset($_GET['mobile']) ? $_GET['mobile'] : '';
	    $email_id = isset($_GET['email']) ? $_GET['email'] : '';
	    $my_address = isset($_GET['address']) ? $_GET['address'] : '';
		$my_form_name = isset($_GET['customer_note']) ? $_GET['customer_note'] : '';
	    
	    $fields['billing']['billing_first_name']['default'] = $first_name;
		$fields['billing']['billing_phone']['default'] = $mobile_no;
	    $fields['billing']['billing_email']['default'] = $email_id;
	    $fields['billing']['billing_address_1']['default'] = $my_address;
	    $fields['billing']['billing_city']['default'] = 'NA';
	    $fields['billing']['billing_postcode']['default'] = 'NA';
		$fields['order']['order_comments']['default'] = $my_form_name;
	   
		return $fields;
	} 
	 
	add_filter( 'woocommerce_billing_fields', 'my_optional_fields' );
	
	function my_optional_fields( $address_fields ) {
		$address_fields['billing_last_name']['required'] = false;
		//$address_fields['billing_city']['required'] = false;
		$address_fields['billing_state']['required'] = false;
		$address_fields['billing_country']['required'] = false;
		//$address_fields['billing_postcode']['required'] = false;
		
		return $address_fields;
	}
	
	/************************** Woocommerce Payment Failed cURL *****************************/
	
	//add_action( 'woocommerce_checkout_order_processed', 'is_express_delivery',  1, 1  );
	add_action( 'woocommerce_order_status_failed', 'my_custom_function_failed');
	
	//function is_express_delivery( $order_id ){
	function my_custom_function_failed( $order_id ){
		// Get $order object from order ID
	 	$order = wc_get_order( $order_id );
	 
		// Now you have access to (see above)...
		$order->get_id();
		
		$first3 = urlencode($order->get_billing_first_name());
	    $mobile3 = urlencode($order->get_billing_phone());
		$email3 = urlencode($order->get_billing_email());
		$formName3 = urlencode($order->get_customer_note());
		
		$ch2 = curl_init('https://www.btpr.online/Capture/Website/Capture.php?License=989810&Name='.$first3.'&Contact='.$mobile3.'&Email='.$email3.'&Website=Sole%20Proprietor&Status=Payment%20Failed&Category=Form&Form%20Name='.$formName3.'');
		curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch2, CURLOPT_POSTFIELDS, $post2);
	
		// execute!
		$response2 = curl_exec($ch2);
	
		// close the connection, release resources used
		curl_close($ch2);
	
		// do anything you want with your response
		var_dump($response2);
	}
	
	/************************** Woocommerce Payment Confirm cURL *****************************/
	
	//add_action( 'woocommerce_checkout_order_processed', 'is_express_delivery',  1, 1  );
	add_action( 'woocommerce_order_status_processing', 'my_custom_function_confirm');
	
	//function is_express_delivery( $order_id ){
	function my_custom_function_confirm( $order_id ){
		// Get $order object from order ID
	 	$order = wc_get_order( $order_id );
	 
		// Now you have access to (see above)...
		$order->get_id();
		
		$first4 = urlencode($order->get_billing_first_name());	
	    $mobile4 = urlencode($order->get_billing_phone());
		$email4 = urlencode($order->get_billing_email());
		$formName4 = urlencode($order->get_customer_note());
		
		$ch3 = curl_init('https://www.btpr.online/Capture/Website/Capture.php?License=989810&Name='.$first4.'&Contact='.$mobile4.'&Email='.$email4.'&Website=Sole%20Proprietor&Status=Payment%20Confirm&Category=Form&Form%20Name='.$formName4.'');
		curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch3, CURLOPT_POSTFIELDS, $post3);
	
		// execute!
		$response3 = curl_exec($ch3);
	
		// close the connection, release resources used
		curl_close($ch3);
	
		// do anything you want with your response
		var_dump($response3);
	}
	
	?>
}
add_filter( 'link_category', 'custom_hook' );