Created
August 3, 2016 22:26
-
-
Save lawkwok/3a0d454b9dd80bde000344a17063f712 to your computer and use it in GitHub Desktop.
WooCoommerce - Modify [woocommerce_order_tracking] shortcode to search by custom order ID instead of the default post ID Raw
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 | |
// function 'get_post_id_by_meta_key_and_value' found at https://gist.github.com/feedmeastraycat/3065969 | |
function get_post_id_by_meta_key_and_value( $key, $value ) { | |
global $wpdb; | |
$meta = $wpdb->get_results("SELECT * FROM `".$wpdb->postmeta."` WHERE meta_key='".$wpdb->escape($key)."' AND meta_value='".$wpdb->escape($value)."'"); | |
if (is_array( $meta ) && !empty( $meta ) && isset( $meta[0]) ) { | |
$meta = $meta[0]; | |
} | |
if ( is_object( $meta ) ) { | |
return $meta->post_id; | |
} | |
else { | |
return false; | |
} | |
} | |
add_filter( 'woocommerce_shortcode_order_tracking_order_id', 'search_by_invoice_order_number' ); | |
function search_by_invoice_order_number( $order_id ) { | |
$order_id = get_post_id_by_meta_key_and_value( '_wcpdf_invoice_number', $order_id ); | |
return $order_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment