How to add package section in Receiving Addon Page or Barcode Scanning page

Add this code to your functions.php in your current theme.

[simple-paywall should_buy=”true” products=”19020″]

add_action( 'wpcr_after_save','wpcr_add_package', 10, 2);
function wpcr_add_package($shipment_id, $form_data){
   	
foreach($form_data as $x => $val) {	
	$pattern = "/[\[\]]/";
	$components = preg_split($pattern, $x);
		if($components[0]=='wpc-multiple-package'){
			$wpc_multiple_package[$components[1]]["$components[3]"] = $val;
		}
	}
	update_post_meta( $shipment_id,	'wpc-multiple-package',maybe_serialize($wpc_multiple_package)	 );
}
add_action( 'wpcr_settings_row','custom_add_setting_row', 10);

function custom_add_setting_row($options){
?>
<tr>
			<th scope="row"><?php esc_html_e('Add package section when shipment if not found?','wpcargo-receiving'); ?></th>
			<td><input type="checkbox" name="wpcargo_receiving_settings[wpcargo_add_package_section]" <?php checked(isset($options['wpcargo_add_package_section']), 1); ?> value="1"></td>
		</tr>		
<?php 
}
    add_action( 'wpcr_after_receiving_form_fields', 'wpcfe_shipment_multipackage_template' );
add_action( 'wpcr_after_receiving_shipment_fields', 'wpcr_toggle_multipackage_template', 10, 1 );
    function wpcr_toggle_multipackage_template($options){
?>
<script> 
 
// Adding dynamic capabilities while using PHP values
window.onload = function() {
 
    document.getElementById('package_id').style.display = 'none'; 
    document.getElementById('submit').style.display = 'none'; 
 
}
 
function togglePackagesSection() {
 
    const addWhenShipmentNotFoundCheckbox = document.getElementById('add-not-found');
    const packagesSection = document.getElementById('package_id');
    const receivingForm = document.getElementById('wpc-receiving');
    <?php $options = get_option('wpcargo_receiving_settings'); ?>
    const addPackagesSectionIfNotFound = <?php echo(isset($options['wpcargo_add_package_section']) ? 'true' : 'false'); ?>;
 
    if (addWhenShipmentNotFoundCheckbox.checked && addPackagesSectionIfNotFound) {
 
        packagesSection.style.display = 'block';
        receivingForm.action = 'can-add';
 
    }
 
    if (!addWhenShipmentNotFoundCheckbox.checked) {
 
        packagesSection.style.display = 'none';
        receivingForm.action = 'cannot-add';
 
    }
 
}
 
</script>
<?php 
}

[/simple-paywall]

0
    0
    Your Cart
    Your cart is emptyReturn to Shop