Created
September 11, 2024 09:33
-
-
Save webtoffee-git/01c3a612f85cca52ac206e617ca5fc8a to your computer and use it in GitHub Desktop.
Code snippet to remove address fields from "Form address" in the Shipping label document - By WebToffee(WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Do not copy this line of code | |
add_filter('wf_pklist_alter_shipping_from_address', 'wt_pklist_alter_from_addr', 10, 3); | |
function wt_pklist_alter_from_addr($fromaddress, $template_type, $order) { | |
if ( 'shippinglabel' === $template_type ) { | |
// Define address fields to remove from the "From" address | |
$address_fields = [ | |
'address_line1', | |
'address_line2', | |
'city', | |
'state', | |
'country', | |
'postcode', | |
]; | |
foreach ( $address_fields as $field ) { | |
if ( ! empty( $fromaddress[$field] ) ) { | |
unset($fromaddress[$field]); | |
} | |
} | |
// Optionally add a new custom field to the "From" address | |
// $fromaddress['new_field'] = 'new field value'; | |
} | |
return $fromaddress; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment