Overriding Plugin function in your child theme

Question

Plugin actions

        $this->loader->add_action( 'wp_ajax_woo_amc_get_cart', $plugin_public, 'show_cart_items_html' );
    $this->loader->add_action( 'wp_ajax_nopriv_woo_amc_get_cart', $plugin_public, 'show_cart_items_html' );

Plugin function

public function show_cart_items_html(){
        $type = sanitize_text_field($_POST['type']);
        $cart = array(
            'html' => 0,
            'count' => 0,
            'total' => 0,
        );

        if ($type) {
            $items = WC()->cart->get_cart();
            if ($type == 'center') {
                $template_type_items = 'items_center';
            } else {
                $template_type_items = 'items_side';
            }
            ob_start();
            // include(plugin_dir_path(dirname(__FILE__)) . 'templates/' . $template_type_items . '.php');
        $custom_templates_path = get_stylesheet_directory().'/woocommerce-ajax-mini-cart';

        if ( file_exists( $custom_templates_path.'/'.$template_type_items.'.php' ) ) {
            $template_items_path = $custom_templates_path.'/'.$template_type_items.'.php';
        } else {
            $template_items_path = plugin_dir_path( dirname( __FILE__ ) ).'templates/'.$template_type_items.'.php';
        }

         if ( file_exists( $custom_templates_path.'/'.$template_type_items.'.php' ) ) {
            require_once $custom_templates_path.'/'.$template_type_items.'.php';
        } else {
            require_once plugin_dir_path( dirname( __FILE__ ) ).'templates/'.$template_type_items.'.php';
        }

        if ( file_exists( $custom_templates_path.'/button.php' ) ) {
            require_once $custom_templates_path.'/button.php';
        } else {
            require_once plugin_dir_path( dirname( __FILE__ ) ).'templates/button.php';
        }


            $output = ob_get_contents();
            ob_end_clean();
            $cart['html'] = $output;
            $cart['count'] = WC()->cart->cart_contents_count;
            $cart['total'] = WC()->cart->get_cart_total();
            $cart['nonce'] = wp_create_nonce( 'woo-amc-security' );
        }

        echo json_encode($cart);
        wp_die();
    }

In Child Theme

I want to override the ** show_cart_items_html() ** function with my function in the child theme.

Does anyone knows how’s this possible? Thanks in advance.

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/overriding-plugin-function-in-your-child-theme/">

Overriding Plugin function in your child theme</a>
0
, , , Gaurav Chauhan 8 months 0 Answers 61 views 0

Leave an answer