WordPress的:不能通过functions.php写在页面上

时间:2019-11-12 18:12:52

标签: wordpress woocommerce e

在我的functions.php上添加此代码时,我得到了JavaScript,但没有得到回显。 如果我添加一个简单的回显“测试”;它也不会出现在我的页面源中。

function qreuz_google_customer_reviews_optin( $order_id ) {
    // this is not working
     echo 'TEST';

    // THIS CODE IS VISIBLE ON THE PAGE SOURCE SO IT IS WORKING 
    $order = new WC_Order( $order_id );
    $qreuz_google_customer_reviews_opt_in_script = '            
              window.renderOptIn = function() {
                window.gapi.load(\'surveyoptin\', function() {
                  window.gapi.surveyoptin.render(
                    {
                      "merchant_id": "123456", 
                      "order_id": "' . $order->get_order_number() . '",
                      "email": "' . $order->get_billing_email() . '",
                      "delivery_country": "' . $order->get_billing_country() . '",
                      "opt_in_style": "CENTER_DIALOG"
                    });
                });
              }';
    wp_register_script( 'qreuz_google_customer_reviews_opt_in_script', '', '', 'false', 'true' );
    wp_enqueue_script( 'qreuz_google_customer_reviews_opt_in_script' );
    wp_add_inline_script( 'qreuz_google_customer_reviews_opt_in_script', $qreuz_google_customer_reviews_opt_in_script );
}
add_action( 'woocommerce_thankyou', 'qreuz_google_customer_reviews_optin', 10, 1 );

有人知道为什么吗?

0 个答案:

没有答案