如何在woocommerce插件类本身中获取插件终点URL?

时间:2019-01-28 11:52:38

标签: php woocommerce

我正在构建woocommerce自定义支付网关插件,我需要在类文件本身中获取插件功能端点url,以及如何获取端点url。我尝试在构造中注册该钩子,并在javscript中调用该方法,但收到400错误请求。

//plugin class file
function __construct(){
 add_action('wc_ajax_get_process_payment', array( $this,'get_process_payment'));
             add_action('wc_ajax_nopriv_get_process_payment',array( $this,'get_process_payment') );
}


                  <script>              
                var onSuccess = function (response) { 
                     var ajaxurl = "<?php echo WC_AJAX::get_endpoint( 'get_process_payment' ); ?>";


                    jQuery.ajax({
                      type: "GET", 
                      url: ajaxurl,
                      dataType : "JSON",
                      data : {action: "get_process_payment"},
                      //cache: false, 
                      success: function(response){
                        alert(response);
                      }
                    });

</script>

function get_process_payment(){
echo "hi";
exit;
}

0 个答案:

没有答案