Avada theme not appearing functions in functions.php file for woocommerce

35 Views Asked by At

I am trying to add a custom dynamic QR code image from order variables to Woocommerce thankyou page.

The code what I am trying to add into functions.php file is below:

add_action( 'woocommerce_thankyou', 'display_order_received_qr_code', 10, 1 );
    function display_order_received_qr_code( $order_id ) { 
        $order = wc_get_order($order_id);
    
        printf('<img class="qrcodecz" alt="QR platba" src="%s" />', 
            add_query_arg( array(
                'accountNumber' => '2202681982',
                'bankCode'      => '2010',
                'amount'        => $order->get_subtotal(),
                'currency'      => 'CZK',
                'vs'            => $order->get_order_number(),
                'message'       => 'svetvramu.cz',
                'size'          => 200,
            ), 'https://api.paylibo.com/paylibo/generator/czech/image' ),
        );
    }

Unfortunately it is not working, nothing appeared on my thank you page. I have read some forums or advices (for example this link: https://avada.io/woocommerce/docs/customize-thank-you-page.html) and I suppose the code what I am using is correct.

In the same file (functions.php) I am using more actions and all of them worked well.

Thank you for any hint!

1

There are 1 best solutions below

1
Snuffy On

Try the following corrections in your function

add_action( 'woocommerce_thankyou', 'display_order_received_qr_code', 10, 1 );
function display_order_received_qr_code( $order_id ) { 
    $order = wc_get_order($order_id);
    $api_url = 'https://api.paylibo.com/paylibo/generator/czech/image';

    $parameters = array(
        'accountNumber' => '2202681982',
        'bankCode'      => '2010',
        'amount'        => $order->get_subtotal(),
        'currency'      => 'CZK',
        'vs'            => $order->get_order_number(),
        'message'       => 'svetvramu.cz',
        'size'          => 200,
    );

    // Build the query string
    $query_string = http_build_query($parameters);

    // Final API URL with parameters
    $api_url_with_params = $api_url . '?' . $query_string;

    printf('<img class="qrcodecz" alt="QR platba" src="%s" />', $api_url_with_params);
}