function set_global_field_key() {
$billing_state_code = get_field('billing_state_code');
if($billing_state_code == 'DL'){
$numeric_state_code = 07;
}
update_option('numeric_state_code', $numeric_state_code);
}
add_action('wpi_invoice_information_meta', 'set_global_field_key');
I have tried this too but the value of numeric_state_code is not being updated. Any idea how to achieve this?
Plugin Contributor
dwpriv
(@dwpriv)
@anonymous2k20
wpi_invoice_information_meta is not a filter of ours. Are you using a different invoice plugin? If this is a typo, you can try using your code in a filter of ours like wpo_wcpdf_after_billing_address. You can see more of our filters here and here.
Updated the hook with the one you suggested. The code is still not working. I have tried fetching the field key numeric_state_code in the customisation section of the plugin but it doesn’t seem to be fetching the same. Could you please suggest any solutions? @dwpriv
Plugin Contributor
dwpriv
(@dwpriv)
@anonymous2k20
could you share your code here, please?
This is the code I’ve added in the functions.php file of my child theme,
function set_global_field_key() {
$billing_state_code = get_field('billing_state_code');
if($billing_state_code == 'DL'){
$numeric_state_code = 07;
}
update_option('numeric_state_code', $numeric_state_code);
}
add_action('wpo_wcpdf_after_billing_address', 'set_global_field_key', 10, 2);
The code I’ve added in the customisation tab of the plugin
State code: {{numeric_state_code}}
What I’m trying to achieve?
I am trying to get the billing_state_code from the individual order and based on the state I would like to assign a numerical which will be printed below the billing address in the invoice. The code is only a sample, I will be adding the numerical for 28 states in India. If you could please guide me that would be great! @dwpriv
Plugin Contributor
dwpriv
(@dwpriv)
@anonymous2k20
You can print the state code to the invoice once you’ve gotten it’s value. Here’s an example:
`
function set_global_field_key() {
$billing_state_code = get_field('billing_state_code');
if($billing_state_code == 'DL'){
$numeric_state_code = 07;
}
update_option('numeric_state_code', $numeric_state_code);
echo '<br>State Code: ' . $numeric_state_code . '<br>';
}
add_action('wpo_wcpdf_after_billing_address', 'set_global_field_key', 10, 2);
`
The above answer did not work, but on the brighter side, using your inputs, I have found the solution for the same.
add_action('wpo_wcpdf_after_billing_address', 'set_global_field_key', 10, 2);
function set_global_field_key($document_type, $order) {
$tax_order = $order->get_type() == 'shop_order_refund' ? wc_get_order( $order->get_parent_id() ) : clone $order;
$billing_state = $tax_order->get_billing_state();
if($billing_state == "TS"){
$numeric_state_code = "36";
}
if($billing_state == "DL"){
$numeric_state_code = "07";
}
update_option('numeric_state_code', $numeric_state_code);
echo '<br>State Code: ' . $numeric_state_code . '<br>';
}
Thank you so much for pointing me in the right direction! @dwpriv
Plugin Contributor
dwpriv
(@dwpriv)
@anonymous2k20
Glad to see the issue is resolved π