L
L
ligisayan2016-01-05 15:13:23
WordPress
ligisayan, 2016-01-05 15:13:23

Why is the error being thrown: call to underfined function?

Hello. I have a store on wordpress + woocommerce. In the configuration file I add a hook with the functionality I need

if (!class_exists('MAD_WOOCOMMERCE_CONFIG')) {
  class MAD_WOOCOMMERCE_CONFIG {
    function __construct() {
      $this->woocommerce_add_hooks();
                }
public function woocommerce_add_hooks() {
  add_action('woocommerce_single_product_summary', array(&$this, 'mad_woocommerce_free_gifts'), 16);
 }
                	public static function get_free_products( $options = array(), $limit = 15 )
  {
    $args = array(
        'post_type' => 'product',
        'post_status' => 'publish',
        'posts_per_page' => $limit,
        'cache_results' => false,
        'no_found_rows' => true
      );

    //merge default and user options
    $args = array_merge($args, $options);

    $products = new WP_Query( $args );
    wp_reset_postdata();

    return $products;
  }
        public function get_free_product_details( $product_id )
  {
    $options = array( 'p' => $product_id );
    $product_details = self::get_free_products( $options );

    $wfg_product_details = array();
    if( !empty($product_details) && !empty($product_details->posts) ) {
      $wfg_product_details['detail'] = $product_details->post;
      $product_image = wp_get_attachment_image_src( get_post_thumbnail_id( $product_details->post->ID ), 'thumbnail' );
      $wfg_product_details['image'] = isset($product_image[0]) ? $product_image[0] : false;
    }
    return (object) $wfg_product_details;
  }
        
        function mad_woocommerce_free_gifts() {
    global $product;
        $wfg_product_details = array();
        $wfg_free_products[] = get_free_product_details( $product );
        var_dump($wfg_free_products);
       }
   }
}

Corrected according to the recommendations - somehow it should be so

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2016-01-05
@ligisayan

well, as far as I understand, this is inside a certain class, get_free_product_details ( ) is a class method, so it should be like this,
well, apparently, you need to pass the product ID to this method, and you pass the entire product object

M
Mikhail Osher, 2016-01-05
@miraage

The penultimate line calls a function that is unknown at this stage of execution.
I will assume that you missed require_once somewhere and / or made a mistake in the function name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question