Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

What is causing syntax error?

+13 votes
asked Dec 29, 2021 by David Fingerlos (220 points)

ERROR: 

syntax error, unexpected ''<a href="javascript:window.pr' (T_CONSTANT_ENCAPSED_STRING)
CODE (second line appears to be the issue):

function isa_get_wc_print_receipt_link() {

    return '<a href="javascript:window.print()" id="wc-print-button">Print receipt</a>';

}

/**

 * Add "Print receipt" link to WooCommerce View Order page

 */

function isa_woo_view_order_print_receipt() {

    echo isa_get_wc_print_receipt_link();

}

add_action( 'woocommerce_view_order', 'isa_woo_view_order_print_receipt', 8 );

/**

 * Add "Print receipt" link to WooCommerce Order Received page TOP

 */

function isa_woo_order_print_receipt_top( $text, $order ) {

    $out = isa_get_wc_print_receipt_link();

    return $out . ' ' . $text;

}

add_filter( 'woocommerce_thankyou_order_received_text', 'isa_woo_order_print_receipt_top', 999, 2);

2 Answers

0 votes
answered Dec 30, 2021 by Peter Minarik (84,720 points)
What programming language is this?

Have you shared the entire code?
0 votes
answered Jan 2, 2022 by xDELLx (10,500 points)
edited Jan 2, 2022 by xDELLx

Searching for error, T_CONSTANT_ENCAPSED_STRING suggests not to mix double quotes & single quote string.

Best option would be to use double quotes & use escape char for nested quotes, like below:

function isa_get_wc_print_receipt_link() {

    return "<a href=\"javascript:window.print()\" id=\"wc-print-button\">Print receipt</a>";

}

src: https://stackoverflow.com/questions/13565768/php-syntax-error-unexpected-t-constant-encapsed-string

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...