• Hi,

    I’m trying to write a custom Code Snippet to fetch tracking information for orders.
    I’m using the sample code given on https://www.zorem.com/docs/woocommerce-advanced-shipment-tracking/compatibility/developers/

    Here’s the code I’m using:

    if ( function_exists( 'ast_get_tracking_items' ) ) {
    		$tracking_items = ast_get_tracking_items($order_id);
    		print_r($tracking_items);
    	} 

    It works as desired if I put the code in the Snippet body. But if I put the code inside a function, the if condition is never true. Can you help me debug or recommend alternate solution?

    • This topic was modified 3 years, 2 months ago by dawgiebowl.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Your code is wrong. use something like this

    /**
     * Display the track items from order id.
     */
    function custom_display_tracking_items() {
    	if ( function_exists( 'ast_get_tracking_items' ) ) {
    		// Change your order id.
    		$order_id       = 0;
    		$tracking_items = ast_get_tracking_items( $order_id );
    		print_r( $tracking_items );
    	}
    }
    add_action( 'init', 'custom_display_tracking_items', 20 );

    Your code should execute after the init action is done, so that all the required things could load first then you run your custom code.

    Plugin Author Zorem

    (@zorem)

    Ok, We will change this code in the next version of the plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘ast_get_tracking_items not working’ is closed to new replies.