覆盖插件功能以在未登录的情况下显示发票

时间:2018-09-28 作者:Adrian

我正在使用WooCommerce Print Invoice 用于打印发票的插件。现在我正在为我的网站开发Cordova应用程序,我需要能够从wordpress查看发票。

插件具有隐藏或重定向页面的功能,如果您未登录。

public function print_document_action() {

        // listen for \'print\' action query string
        if (isset($_GET[\'wc_pip_document\'], $_GET[\'wc_pip_action\']) && \'print\' === $_GET[\'wc_pip_action\']) {

            // sanity check, if user is not logged in, prompt to log in
            if (!is_user_logged_in()) {
                wp_redirect(wc_get_page_permalink(\'myaccount\'));
                exit;
            }

            $nonce = isset($_REQUEST[\'_wpnonce\']) ? $_REQUEST[\'_wpnonce\'] : \'\';

            // security admin/frontend checks
            if (!$nonce || !wp_verify_nonce($nonce, \'wc_pip_document\')) {
                die(__(\'You are not allowed to view this page.\', \'woocommerce-pip\'));
            }
是否可以从函数中覆盖此内容。php?

尝试再次使用整个函数,但没有以下行:

add_filter(\'print_document_action\', \'showInvoices\', $priority = 9999, $args = 1);
function showInvoices() {
    // same function without sanity check and security admin/frontend checks
}
还尝试使用JSON API插件生成nounce,并按如下方式运行页面:

site.com/orders/?wc_pip_action=print&wc_pip_document=invoice&order_id=\'+id+\'&_wpnonce=\'+nonce;
这也不起作用。有什么想法吗?

1 个回复
SO网友:Ash0ur

尝试从过滤器中删除插件函数。

您确定插件函数和过滤器的名称相同吗!

*您需要知道插件函数在remove\\u filter中使用它的优先级,我假设它是默认值(10)。

remove_filter( \'print_document_action\', \'print_document_action\', 10 );
然后将函数添加到过滤器。

add_filter(\'print_document_action\', \'showInvoices\', $priority = 9999, $args = 1);

结束

相关推荐

Calculations in functions.php

我为自己创建了一个发票主题,并试图在自定义列中获取发票总额。我已经尝试调整模板页面中使用的代码,以便在函数中显示这一点。php文件,但它不工作。我的乘法操作数出现了一个操作数错误,我不知道为什么。这是我的代码(如有任何帮助,将不胜感激)。if( $column_name == \'invoice_total\' ) { $hours = 0; // This allows counting of each sub_field //* Set repeater va