【问题标题】:How to include custom php file inside wordpress plugin directory?如何在 wordpress 插件目录中包含自定义 php 文件?
【发布时间】:2019-06-22 08:54:43
【问题描述】:

我正在开发自定义支付网关,我需要通过插件目录中的自定义 php 文件处理 tranasaction_id 和其他支付详细信息。此外,我得到了 4 次 ajax 请求加载响应,我得到了如何避免它。

// plugin class file payment-gateway.php

//response.status ="approved";
//response.transaction_id ="324234";
var dataString = JSON.stringify(response);                       
                jQuery.ajax({
                     type : "POST",
                     dataType : "json",
                     contentType: "application/json",
                     url: '<?php echo plugins_url().'/custom-woocommerce-gateway/includes/custom_php_file.php'; ?>',
                    data: {myData:dataString},
                     success: function(response) {


                        }
                        }); 

/*custom-woocommerce-gateway/includes/custom_php_file.php */
<?php 
//define the wc functions

print_r($_REQUEST);
process the payment details like woocommerce

exit;

【问题讨论】:

    标签: php jquery wordpress plugins woocommerce


    【解决方案1】:

    如果此功能位于插件的文件中,则应尝试使用plugin_dir_path()

     url: '<?php echo plugin_dir_path( __FILE__ ) . 'includes/custom_php_file.php'; ?>',
    

    但是使用提供的代码和详细信息,没有人可以解决您的 ajax 多请求加载问题。

    在 StackOverFlow 中,您不能一次提出多个问题。您需要在当时拆分并提出问题,“包括所需的行为、特定问题或错误以及在问题本身中重现它所需的最短代码。没有明确的问题问题陈述对其他读者没有用”。见:How to create a Minimal, Complete, and Verifiable example

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      相关资源
      最近更新 更多