PHP code example of tombroucke / otomaties-woocommerce-extra-checkout-steps

1. Go to this page and download the library: Download tombroucke/otomaties-woocommerce-extra-checkout-steps library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tombroucke / otomaties-woocommerce-extra-checkout-steps example snippets


	add_shortcode('checkout_billing_information', function () {
		return view('shortcodes.checkout-personal-details', [
			'adminPostUrl' => admin_url('admin-post.php'),
 			'data' => WooCommerceExtraCheckoutSteps()->make(\Otomaties\WooCommerceExtraCheckoutSteps\Helpers\Steps::class)->find(get_the_ID())->getData(),
		])->toHtml();
	});
	

	add_action('woocommerce_extra_checkout_steps_verify_fields', function($stepName, $currentStep, $nextStep, $steps) {
	if ($stepName === 'personal_details') {
			$fields = [
				'billing_first_name' => [
					'label' => __('First name', 'text-domain'),
					'validate' => [
						'alidate' => [' null);
						},
						'message' => sprintf(__( '%s is not a valid postcode / ZIP.', 'woocommerce' ), '<strong>' .  __('Postcode', 'remmerie') . '</strong>')
					    ]
					]
				],
				'billing_phone' => [
					'label' => __('Phone', 'remmerie'),
					'validate' => [
					    ', '<strong>' .  __('Email', 'remmerie') . '</strong>')
					    ]
					]
				],
				// ...
			];
	    $currentStep->verifyFields($fields);
	}
	}, 10, 4)
	

	add_action('woocommerce_extra_checkout_steps_data_saved', function($callback, $data, $currentStep, $nextStep) {
		// save the data
	}, 10, 4)
	

	add_action('woocommerce_checkout_order_processed', function ($orderId, $postedData, $order) {
		WooCommerceExtraCheckoutSteps()->make(\Otomaties\WooCommerceExtraCheckoutSteps\Helpers\Steps::class)
			->each(function($step) {
				$stepData = $step->getData();
				$order->update_meta_data('custom_field', $stepData['custom_field']);
				$order->save();
			});
	});