【问题标题】:How to change this complex function to a simple redirect如何将这个复杂的功能更改为简单的重定向
【发布时间】:2011-12-30 05:09:11
【问题描述】:

我一直在对 wordpress 电子商务插件进行一些更改,并且我已经提取了大量功能以使其更简单以满足我的需求。现在按下购买按钮后它不会重定向到感谢页面,因为该函数使用了一些我删除的变量,例如order_id等。

我已经为此工作了几个小时,我想要做的只是单击购买按钮重定向到thankyou.php。 (我现在知道它使用 ajax,我也不介意使用它)我不需要它来处理 processpayment 功能或类似的东西。真的很简单。

这是我正在使用的代码和函数:

非常感谢!!!

输入元素:

<div id="payment">

        <div class="form-row">

            <noscript><?php _e('Since your browser does not support JavaScript, or it is disabled, please ensure you click the <em>Update Totals</em> button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'jigoshop'); ?><br/><input type="submit" class="button-alt" name="update_totals" value="<?php _e('Update totals', 'jigoshop'); ?>" /></noscript>

            <?php jigoshop::nonce_field('process_checkout')?>
            <input type="submit" class="button-alt" name="place_order" id="place_order" value="<?php _e('Next Step', 'jigoshop'); ?>" />

            <?php do_action( 'jigoshop_review_order_before_submit' ); ?>

            <?php if (get_option('jigoshop_terms_page_id')>0) : ?>
            <p class="form-row terms">
                <label for="terms" class="checkbox"><?php _e('I accept the', 'jigoshop'); ?> <a href="<?php echo get_permalink(get_option('jigoshop_terms_page_id')); ?>" target="_blank"><?php _e('terms &amp; conditions', 'jigoshop'); ?></a></label>
                <input type="checkbox" class="input-checkbox" name="terms" <?php if (isset($_POST['terms'])) echo 'checked="checked"'; ?> id="terms" />
            </p>
            <?php endif; ?>

            <?php do_action( 'jigoshop_review_order_after_submit' ); ?>

        </div>

    </div>

checkout.class.php:

        // Process Payment
                    $result = $available_gateways["cheque"]->process_payment( $order_id );


                    // Redirect to success/confirmation/payment page

                        if (is_ajax()) : 
                            ob_clean();
                            echo json_encode($result);
                            exit;
                        else :
                            wp_safe_redirect( $result['redirect'] );
                            exit;
                        endif;


                else :

                    // No payment was required for order
                    $order->payment_complete();

                    // Empty the Cart
                    jigoshop_cart::empty_cart();

                    // Redirect to success/confirmation/payment page
                    $checkout_redirect = apply_filters( 'jigoshop_get_checkout_redirect_page_id', get_option( 'jigoshop_thanks_page_id' ) );
                    if (is_ajax()) : 
                        ob_clean();
                        echo json_encode( array( 'redirect' => get_permalink( $checkout_redirect ) ) );
                        exit;
                    else :
                        wp_safe_redirect( get_permalink( $checkout_redirect ) );
                        exit;
                    endif;

                endif;

                // Break out of loop
                break;

处理支付功能:

function process_payment() {


        // Remove cart
        jigoshop_cart::empty_cart();

        // Return thankyou redirect
        $checkout_redirect = apply_filters( 'jigoshop_get_checkout_redirect_page_id', get_option( 'jigoshop_thanks_page_id' ) );
        return array(
            'result'    => 'success',
            'redirect'  => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink( $checkout_redirect )))
        );

    }

这是我从 firebug 得到的错误详情:

打开调试后,出现以下错误:

注意:未定义索引:aiosp_enabled in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/all_in_one_seo_pack.php 710号线

注意:未定义索引:aiosp_enabled in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/all_in_one_seo_pack.php 710号线

注意:使用未定义的常量 PLUGIN_URL - 假定为“PLUGIN_URL” /home2/findmyki/public_html/bolistylus/wp-content/plugins/wp-google-fonts/google-fonts.php 在第 81 行

注意:使用未定义的常量 PLUGIN_PATH - 假定为“PLUGIN_PATH” 在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/wp-google-fonts/google-fonts.php 在第 82 行

注意:未定义的索引:主机在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jetpack/jetpack.php 2306行

注意:未定义索引:shipping-first_name in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 198 行

注意:未定义索引:shipping-last_name in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 199 行

注意:未定义索引:shipping-company in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 200 行

注意:未定义索引:送货地址在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 201行

注意:未定义索引:shipping-address-2 in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 202 行

注意:未定义索引:shipping-city in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 203 行

注意:未定义索引:shipping-state in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 204 行

注意:未定义索引:shipping-postcode in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 205 行

注意:未定义索引:shipping-country in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 206 行

重要提示:

注意:未定义变量:user_id in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 211行

注意:未定义索引:order_cmets in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 256 行

注意:未定义索引:billing-company in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 264 行

注意:未定义索引:帐单地址在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 265 行

注意:未定义索引:billing-address-2 in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 266 行

注意:未定义索引:billing-city in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 267 行

注意:未定义索引:billing-postcode in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 第268行

注意:未定义索引:billing-country in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 第 269 行

注意:未定义索引:帐单状态在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 270 行

注意:未定义索引:billing-phone in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 272 行

注意:未定义索引: shipping_method in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 282 行

注意:未定义索引:payment_method in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 283 行

注意:未定义索引:aiosp_edit in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php 1105行

注意:未定义索引:nonce-aioseop-edit in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php 1106行

重要提示:

注意:未定义变量:user_id in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 364 行

注意:未定义变量:available_gateways in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 第 379 行

重要提示:

致命错误:调用成员函数 process_payment() 非对象在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 第 379 行

注意:未定义索引:aiosp_enabled in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/all_in_one_seo_pack.php 710号线

注意:未定义索引:aiosp_enabled in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/all_in_one_seo_pack.php 710号线

注意:使用未定义的常量 PLUGIN_URL - 假定为“PLUGIN_URL” /home2/findmyki/public_html/bolistylus/wp-content/plugins/wp-google-fonts/google-fonts.php 在第 81 行

注意:使用未定义的常量 PLUGIN_PATH - 假定为“PLUGIN_PATH” 在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/wp-google-fonts/google-fonts.php 在第 82 行

注意:未定义的索引:主机在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jetpack/jetpack.php 2306行

注意:未定义索引:shipping-first_name in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 198 行

注意:未定义索引:shipping-last_name in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 199 行

注意:未定义索引:shipping-company in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 200 行

注意:未定义索引:送货地址在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 201行

注意:未定义索引:shipping-address-2 in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 202 行

注意:未定义索引:shipping-city in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 203 行

注意:未定义索引:shipping-state in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 204 行

注意:未定义索引:shipping-postcode in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 205 行

注意:未定义索引:shipping-country in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 206 行

注意:未定义变量:user_id in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 211行

注意:未定义索引:order_cmets in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 256 行

注意:未定义索引:billing-company in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 264 行

注意:未定义索引:帐单地址在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 265 行

注意:未定义索引:billing-address-2 in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 266 行

注意:未定义索引:billing-city in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 267 行

注意:未定义索引:billing-postcode in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 第268行

注意:未定义索引:billing-country in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 第 269 行

注意:未定义索引:帐单状态在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 270 行

注意:未定义索引:billing-phone in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 272 行

注意:未定义索引: shipping_method in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 282 行

注意:未定义索引:payment_method in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 283 行

注意:未定义索引:aiosp_edit in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php 1105行

注意:未定义索引:nonce-aioseop-edit in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php 1106行

注意:未定义变量:user_id in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 在第 364 行

注意:未定义变量:available_gateways in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 第 379 行

重要!!!!:

致命错误:调用成员函数 process_payment() 非对象在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php 第 379 行

注意:未定义索引:aiosp_enabled in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/all_in_one_seo_pack.php 710号线

注意:未定义索引:aiosp_enabled in /home2/findmyki/public_html/bolistylus/wp-content/plugins/all-in-one-seo-pack/all_in_one_seo_pack.php 710号线

注意:使用未定义的常量 PLUGIN_URL - 假定为“PLUGIN_URL” /home2/findmyki/public_html/bolistylus/wp-content/plugins/wp-google-fonts/google-fonts.php 在第 81 行

注意:使用未定义的常量 PLUGIN_PATH - 假定为“PLUGIN_PATH” 在 /home2/findmyki/public_html/bolistylus/wp-content/plugins/wp-google-fonts/google-fonts.php 在第 82 行

【问题讨论】:

  • 您没有提供足够的信息来回答这个问题。
  • 使用 FireBug 调试 ajax 请求 getfirebug.com 它应该会打印出出错信息。
  • @satrun77 jigoshop-checkout 功能出错。
  • @novicePrgrmr 您可以发布包含所有详细信息的完整错误消息。错误在哪个文件、行号、错误消息和来自 ajax 请求的响应文本。
  • @satrun77 完成。这就是我从萤火虫那里得到的

标签: php wordpress jigoshop


【解决方案1】:

响应选项卡中应该有一些文本或 json 字符串,但它是空的。这可能是由于服务器中的 php 设置被设置为隐藏所有错误消息而隐藏的 php 错误的结果,这很好。

打开调试参见http://codex.wordpress.org/Editing_wp-config.php#Debug 并重试。响应选项卡中应该有一些文本。

更新开启调试:

这里看起来有些不对劲。发送 Ajax 请求时是否收到这些错误?

查看这些错误,我可以看到您有致命错误,它必须停止代码执行。

Fatal error: Call to a member function process_payment() on a non-object in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php on line 379

您已经修改了原始文件 jigoshop_checkout.class.php,因此我很难找到这些错误的确切行。但是“注意:未定义的索引:”表示该行中有一个数组变量没有索引...

在这个文件中调用了一次方法'process_payment'

// Process Payment
$result = $available_gateways[$this->posted['payment_method']]->process_payment( $order_id );

$available_gateways 是一个包含不同支付方式对象的数组。但是$this->posted['payment_method']中定义的支付方式没有对象

另外,我可以看到变量 $available_gateways 不存在/未定义的另一个错误消息状态

Notice: Undefined variable: available_gateways in /home2/findmyki/public_html/bolistylus/wp-content/plugins/jigoshop/classes/jigoshop_checkout.class.php on line 379

这个变量只能在jigoshop_cart::needs_payment() return true时定义

if (jigoshop_cart::needs_payment()) :
        // Payment Method
        $available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
        if (!isset($available_gateways[$this->posted['payment_method']])) :
                jigoshop::add_error( __('Invalid payment method.','jigoshop') );
        else :
                // Payment Method Field Validation
                $available_gateways[$this->posted['payment_method']]->validate_fields();
        endif;
endif;

【讨论】:

  • 我打开调试,在网站上得到了上述错误。
【解决方案2】:
<input type="button" value="Submit" onClick="location.href='thankyou.php';">

如果您不需要它来做任何其他事情,请尝试。您可能需要编辑 href 以使其到达您想要的位置。它在我的网站上对我有用。

您还可以始终将表单的操作重定向到另一个页面,然后该页面在处理后重定向到感谢页面。

只需使用 header('Location: ');重定向。

【讨论】:

    猜你喜欢
    • 2012-01-15
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-08
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    相关资源
    最近更新 更多