• Resolved pippijn

    (@pippijn)


    Hello,

    The shortcode [pr_dhl_tracking_link product_id=”12345″] is not working.
    The shortcode is not in $shortcode_tags which means it’s not registered. But I’m not sure why..

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Shadi Manna

    (@shadim)

    Can you confirm which country your webshop is in and where you are trying to use the shortcode?

    Thread Starter pippijn

    (@pippijn)

    Country is Netherlands and i’m trying to add the t&t to emails. Because we use Flycart WooCommerce Email Customizer with Drag and Drop Email Builder, the default action “woocommerce_order_details_after_order_table_items” is not called.

    I wrote a php snippet to test the pr_dhl_tracking_link shortcode, but that doesn’t work either:

    add_action( 'wp_loaded','test_code' );
    function test_code() {
    	echo do_shortcode('[pr_dhl_tracking_link product_id="12345"]');
    }

    I also found this code on the support forum:
    echo PR_DHL()->get_pr_dhl_wc_order()->get_dhl_label_tracking( '12345' );
    But that gives the error “Class ‘PR_DHL_API_Factory’ not found in …/public_html/wp-content/plugins/dhl-for-woocommerce/pr-dhl-woocommerce.php:391”

    • This reply was modified 3 years, 5 months ago by pippijn.
    • This reply was modified 3 years, 5 months ago by pippijn.
    Plugin Author Shadi Manna

    (@shadim)

    Are you using DHL Parcel or Deutsche Post? If you are using Deutsche Post, try using the replacement string instead {pr_dhl_tracking_note} within the email.

    Thread Starter pippijn

    (@pippijn)

    We use DHL Parcel.

    I did try to include the string {pr_dhl_tracking_note}, but it just shows {pr_dhl_tracking_note} in the email.

    Plugin Author Shadi Manna

    (@shadim)

    The short code and email reference do not work for DHL Parcel unfortunately.

    Thread Starter pippijn

    (@pippijn)

    Is there no way of adding t&t to the email? All I need is a function call for the url. I’ll create the note myself.

    Plugin Author Shin Ho

    (@shindhl)

    Hi pippijn,

    Thanks for using the DHL for WooCommerce plugin. Unfortunately shortcodes are not supported with DHL Parcel. For direct contact, you can e-mail cimparcel@dhl.com

    If you’re familiar with coding, the function you’re looking for is in:

    includes\controller\class-dhlpwc-controller-mail.php
    DHLPWC_Controller_Mail::add_track_trace_to_completed_order_mail()

    It’s currently not tailored to be used outside of the WooCommerce hook, but can be copied and tuned into a custom snippet.

    Greetings,
    Shin Ho
    Plugin Development Team
    DHL Parcel Netherlands

    Thread Starter pippijn

    (@pippijn)

    Thank you! I figured it out

    @pippijn hoe heb je het opgelost? Ik heb hetzelfde probleem met DHL plugin en Woomail Customizer.

    how did you solve it? I have the same problem with DHL plugin

    Thread Starter pippijn

    (@pippijn)

    This is the function I use to get the T&T urls:

    function get_dhl_parcel_urls( $order_id ) {
    	if ( $order_id ){
    		$locale = str_replace('_', '-', get_locale());
    
    		$order = wc_get_order($order_id);
    		if ( ! $order ){
    			return false;
    		}
            $address = $order->get_address('shipping') ?: $order->get_address();
            $postcode = wc_format_postcode($address['postcode'], $address['country']);
    		
    		$labels = get_post_meta($order_id, '_dhlpwc_order_labels', true);
    		if (!is_array( $labels )) {
    			return false;
    		}
    
            $tracking_codes = array();
            foreach($labels as $label) {
                if (array_key_exists('tracker_code', $label) && empty($label['is_return'])) {
                    $tracking_codes[] = $label['tracker_code'];
                }
            }
    
    		$tracking_codesets = array();
    		foreach($tracking_codes as $tracking_code) {
    			$tracking_codeset = array();
    			$tracking_codeset['url'] = get_tt_url($tracking_code, $postcode, $locale);
    			$tracking_codeset['code'] = $tracking_code;
    			$tracking_codesets[] = $tracking_codeset;
    		}
    		return $tracking_codesets;
    	} else {
    		return false;
    	}
    }
    
    function get_tt_url($tracking_code = null, $postcode = null, $locale = null){
    	$url = 'https://www.dhlparcel.nl/nl/volg-uw-zending-0';
    	$query_args = array();
    	if ($tracking_code !== null) {
    		$query_args['tt'] = urlencode($tracking_code);
    	}
    
    	if ($postcode !== null) {
    		$query_args['pc'] = urlencode($postcode);
    	}
    
    	if ($locale !== null) {
    		$query_args['lc'] = urlencode($locale);
    	}
    
    	return add_query_arg($query_args, $url);
    }

    @pippijn thanks, which shortcode do you use?

    Thread Starter pippijn

    (@pippijn)

    bud88

    (@bud88)

    @pippijn `I’ve already tried a number of things. via custom short code in function.php or via the custom_code.php as the link describes

    But I can’t manage what should be written here? Because I already get to see the URL just not filled

    • This reply was modified 3 years ago by bud88.
    Thread Starter pippijn

    (@pippijn)

    this is the contents of custom_code.php:

    
    <?php
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    // Example for the short code [woo_mb_custom_code type="tracking-code"]
    if(isset($attr['type']) && $attr['type'] == 'tracking-code'){
    	//do_shortcode('[pr_dhl_tracking_link order_id="'. $order->get_id().'"]');
    	$tracking_urls = get_dhl_parcel_urls($order->get_id());
    	if ($tracking_urls){
    		foreach($tracking_urls as $tracking_url) {
    			printf('<a href="%s">Track & Trace - %s</a><br>', $tracking_url['url'], $tracking_url['code']);
    		}
    	}
    }
    

    Use this shortcode where you want the tracking url:
    [woo_mb_custom_code type=”tracking-code”]

    bud88

    (@bud88)

    @pippijn thankss Men!!! I got it work with Woo Mail Customizer know.

    [ec_woo_custom_code type=”tracking-code”]

    Little bit differt.
    https://askerov.ticksy.com/article/15350/

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