在functions.php中创建自定义函数

时间:2019-02-14 15:16:34

标签: javascript wordpress

我已经在wordpress中为我的functions.php创建了代码,但是在代码的某些部分似乎出现了未定义的$错误。这是当我单击流程付款时发生的图像 Errors

这是我的代码:

    function paypalpayment() {
    global $wpdb;
    $user = wp_get_current_user();
    $user_ID = $user->ID;
    $shortcode = $wpdb->get_row("SELECT MAX(ap.pending) AS pending, ap.book_datetime, ap.id, ap.hash FROM ea_appointments AS ap "
            ."INNER JOIN ea_users AS us ON ap.id_users_customer = us.id "
            ."WHERE us.wp_id ='".$user_ID."'");
    $html = '';

    if ($shortcode->pending == ''){
        $html .= '<h1>Processing Error: Appointment has been deleted. </h1>';
        $html .= '<p align="center"><a class="fep-button" style="width: 195px; text-align: center;" href="http://lectiotutoring.co.za/EasyBlue" /> Schedule an appointment</a></p>';
    } else {
        $html .= '<h2>Fee Policy</h2>';
        $html .= '<p>You may reschedule an appointment without charge within 24 hours of your appointment.  Cancelation of an appointment within 24 hours can either result in a refund or a credit for your next appointment per your request. You will need to inform Mr. Tucker on the discussion board about how you would like your cancelation to be handled. If you would like a refund, refunds will be the full amount of the cost of your session minus the PayPal processing fees. There are no refunds for cancelations later than 24 hours in advance. <span class="bigger"><b>If payment is not completed within 10 minutes the appointment will be deleted.</b></span></p>';
        date_default_timezone_set('America/Los_Angeles');
        $refreshtime = strtotime($shortcode->book_datetime) - strtotime("-10 minutes");

        $html .= '<meta http-equiv="refresh" content="';
        $html .=   $refreshtime;
        $html .=  '">';
    if(strtotime($shortcode->book_datetime) > (strtotime("-10 minutes"))){
        $html .= '<style>



        </style>';

        $html .= '<input type="button" id="stepone" onclick="processpaypal()" value="Process Payment">';
        $html .= '<div id="spinner" class="loader" style="display:none"></div>';
        $html .= do_shortcode($shortcode->pending);
        $html .= '<input type="button" onclick="deletapt()" value="Delete Apt.">';
        $html .= '<script>
            cancelurl = "http://lectiotutoring.co.za/EasyBlue/index.php/appointments/cancel/' . $shortcode->hash . '";
            function deletapt(){
                window.location = cancelurl;
            }
            $(document).ready(function() {
                $("input[name=return]").val("http://lectiotutoring.co.za/payment-success/");
                $("input[name=cancel_return]").val(cancelurl);
            });  

            function processpaypal(){
                $("#spinner").css("display","block");
                $("#stepone").css("display","none");
                setTimeout(
                function() 
                {
                    $(".wpi_checkout_submit_btn").click();
                }, 250);                
            }

        </script>';
        }else{
        $html .= '<h4 style="text-align: center;">Time has expired</h4>';
        $html .= '<p align="center"><a class="fep-button" style="width: 195px; text-align: center;" href="http://lectiotutoring.co.za/EasyBlue" /> Schedule an appointment</a></p>';
        }
    }   
    return $html;
}
add_shortcode("paypalpay", "paypalpayment");


//PayPal Callback function that replaces the cryptic suffix with actual service names in patients the WP-Invoice file.
function ea_paypalcallback($transaction_data){
    global $wpdb;
    //Grab Service Name and Date 
    $session_id = $transaction_data[post_data][created_by][0];
    $posturl = $transaction_data[post_data][guid][0];
    $urlArray = explode('=',$posturl);
    $postid = $urlArray[sizeof($urlArray)-1];
    $dummyname = $transaction_data[items][1][name];
    $query = "SELECT concat(eas.name, '  ', DATE_FORMAT(eaa.start_datetime, '%m/%d/%Y') ) FROM ea_services AS eas  " .
    "LEFT JOIN  ea_appointments AS eaa ON eaa.id_services =  eas.id WHERE eaa.pending LIKE '%" . $session_id . "%'";
    $servicename = $wpdb->get_var($query);  
    $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}posts SET post_content = REPLACE(post_content, 'Items: $dummyname', '$dummyname: $servicename') WHERE ID = $postid"));
    $wpdb->query($wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = REPLACE(meta_value, '$session_id', '') WHERE meta_key = 'post_title' AND post_id = $postid"));
    sleep(5);
    $wpdb->query($wpdb->prepare("UPDATE ea_appointments SET pending = '' WHERE pending LIKE '%$session_id%'")); 
}

更新 我收到错误的代码行在这里:

            $(document).ready(function() {
$("input[name=return]").val("http://lectiotutoring.co.za/payment-success/");
                    $("input[name=cancel_return]").val(cancelurl);
                });  



    function processpaypal(){
                    $("#spinner").css("display","block");
                    $("#stepone").css("display","none");

'<input type="button" id="stepone" onclick="processpaypal()" value="Process Payment">';

0 个答案:

没有答案