我有个奇怪的问题,根本找不到解决办法。我想在Woocommerce结账时跟踪下订单按钮的点击,但当我在输入中添加onClick操作时,网站就不会加载。如果我将单qoutes更改为双qoutes站点负载,但不跟踪GA事件。
有人有类似的问题或知道解决方案吗?
<div class="form-row place-order">
<noscript>
<?php echo sprintf( esc_html__( \'Since your browser does not support JavaScript, or it is disabled, please ensure you click the %1$s Update Totals %2$s button before placing your order. You may be charged more than the amount stated above if you fail to do so.\', \'norebro\' ), \'<em>\', \'</em>\' ); ?>
<br/><input type="submit" class="button alt" name="woocommerce_checkout_update_totals" value="<?php esc_attr_e( \'Update totals\', \'norebro\' ); ?>" />
</noscript>
<?php wc_get_template( \'checkout/terms.php\' ); ?>
<?php do_action( \'woocommerce_review_order_before_submit\' ); ?>
<?php echo apply_filters( \'woocommerce_order_button_html\', \'<input type="submit" onClick="ga( \'send\', \'event\', \'button\', \'click\', \'placeorder\' );" class="btn btn-brand full-width" name="woocommerce_checkout_place_order" id="place_order" value="\' . esc_attr( $order_button_text ) . \'" data-value="\' . esc_attr( $order_button_text ) . \'" />\' ); ?>
<?php do_action( \'woocommerce_review_order_after_submit\' ); ?>
<?php wp_nonce_field( \'woocommerce-process_checkout\' ); ?>
</div>
最合适的回答,由SO网友:Morgan Estes 整理而成
您的输入行包含在单引号中,因此当PHP看到该字符串中的单引号时,它会认为您已经处理完该字符串并跳回PHP。
解决此问题的方法是转义字符串中的引号,以便ga()
更改自\'send\'
到\\\'send\\\'
.