Created
September 2, 2020 18:36
-
-
Save juniorthiesen/acc6b8dae631b2a6e51459dc3bca9bd6 to your computer and use it in GitHub Desktop.
plimor
This file contains hidden or 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
add_action( 'wcasn_form_fields', 'wcasn_custom_form_fields' ); | |
function wcasn_custom_form_fields( $order_id ) { ?> | |
<label>Nota Fiscal</label> | |
<input type="text" name="nota_fiscal" class="wcasn-custom-fields" value="" /> | |
<?php } | |
add_filter( 'wc_any_shipping_notify_shipping_company_url', 'filter_wcasn_custom_url_fields', 20, 4 ); | |
function filter_wcasn_custom_url_fields( $url, $slug, $tracking_code, $order ) { | |
if ( $custom_url = $order->get_meta( '_wcasn_' . $tracking_code . '_custom_url' ) ) { | |
return $custom_url; | |
} | |
if ( isset( $_POST['custom_fields'] ) ) { | |
$find_replace = array(); | |
foreach ( $_POST['custom_fields'] as $k => $v ) { | |
$find_replace[ '{' . $k . '}' ] = $v; | |
} | |
$url = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $url ); | |
$order->update_meta_data( '_wcasn_' . $tracking_code . '_custom_url', $url ); | |
$order->save(); | |
} | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment