簡體   English   中英

如何通過wordpress中的functions.php覆蓋父主題的公共靜態功能?

[英]How to override public static function of parent theme through functions.php in wordpress?

這是在父主題中聲明函數的方式,我想更改返回值邏輯,任何人都可以指導我朝着正確的方向前進嗎?

我嘗試使用新邏輯和add_actionfunctions.php添加函數,但這沒有幫助。

add_action('wp_ajax_calculate_price', array($this, 'ajax_calculate_price'));
add_action('wp_ajax_nopriv_calculate_price', array($this, 'ajax_calculate_price'));

public static function ajax_calculate_price( ) {
        $listing_id = $_POST['listing_id'];
        $tickets = isset($_POST['tickets']) ? $_POST['tickets'] : 1 ;


        $normal_price = (float) get_post_meta ( $listing_id, '_normal_price', true);
        $reservation_price  =  (float) get_post_meta ( $listing_id, '_reservation_price', true);
        $services_price = 0;
        if(isset($_POST['services'])){
            $services = $_POST['services'];
            $bookable_services = listeo_get_bookable_services($listing_id);
             $i = 0;
             foreach ($bookable_services as $key => $service) {
                $i++;
                if(in_array('service_'.$i,$services)) {
                  $services_price += (float) preg_replace("/[^0-9\.]/", '', $service['price']);

                }
             } 
        }
        $ajax_out['price'] = ($normal_price * $tickets) + $reservation_price + $services_price;
        wp_send_json_success( $ajax_out );
    }

從您的編碼中,您使用的是 listeo wordpress 主題。 您正在調用函數listeo_get_bookable_services ,該函數在您的主題functions.php可能不可用。 因此,為了使這項工作包括在functions.php 中具有函數listeo_get_bookable_services的類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM