Skip to main content
edited tags
Link
Johansson
  • 15.4k
  • 11
  • 43
  • 79
Gave it a more relevant title
Source Link
helgatheviking
  • 14.5k
  • 8
  • 64
  • 115

Fatal error: Call WooCommerce create new product and add to a member function add_to_cart()cart on a non-object in function.phpform submit

I am customizing woo-commerce plugin to add product from the front end into the cart. I have written the function in functions.php, but i am getting a Fatal error.

Getting this error-->

Fatal error: Call to a member function add_to_cart() on a non-object in
C:\wamp\www\cutting-edge_server\wordpress_theme\wp-content\themes\cutting_age\responsive\functions.php on line 56

Any body have any idea how to resolve it?

My function.php file

if (isset($_POST["addcustomcarts"]))
        {
       echo $_SERVER[QUERY_STRING];
      // echo $_SERVER[REQUEST_URI];
        echo "i am in if";
        //exit();
    add_filter('woocommerce_before_cart', 'customcart');
    
    function customcart() { 
       echo "i am in function";
        
    //global $woocommerce;
    
    $my_post = array(
      'post_title'    => 'My post',
      'post_content'  => 'This is my post.',
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_type'     =>'product'
      
    );
    
    
    // Insert the post into the database
     $product_ID=wp_insert_post( $my_post );
     
     add_post_meta($product_ID, '_regular_price', 100, $unique);
     add_post_meta($product_ID, '_price', 100, $unique);
      add_post_meta($product_ID, '_stock_status', 'instock', $unique);
     
     
      //Getting error on this line.
      $woocommerce->cart->add_to_cart( $product_ID, $quantity=1 );
     
    
     
    
     exit( wp_redirect( home_url( "cart" ) ) );
    }
    
    customcart();
      }

My html file

<form name="addpro" method="post" action="">
    <input type="submit" name="addcustomcarts" value="ADD TOO CART" />
  </form> 

Getting this error-->

Fatal error: Call to a member function add_to_cart() on a non-object in
C:\wamp\www\cutting-edge_server\wordpress_theme\wp-content\themes\cutting_age\responsive\functions.php on line 56

Fatal error: Call to a member function add_to_cart() on a non-object in function.php

I am customizing woo-commerce plugin to add product from the front end into the cart. I have written the function in functions.php, but i am getting a Fatal error. Any body have any idea how to resolve it?

My function.php file

if (isset($_POST["addcustomcarts"]))
        {
       echo $_SERVER[QUERY_STRING];
      // echo $_SERVER[REQUEST_URI];
        echo "i am in if";
        //exit();
    add_filter('woocommerce_before_cart', 'customcart');
    
    function customcart() { 
       echo "i am in function";
        
    //global $woocommerce;
    
    $my_post = array(
      'post_title'    => 'My post',
      'post_content'  => 'This is my post.',
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_type'     =>'product'
      
    );
    
    
    // Insert the post into the database
     $product_ID=wp_insert_post( $my_post );
     
     add_post_meta($product_ID, '_regular_price', 100, $unique);
     add_post_meta($product_ID, '_price', 100, $unique);
      add_post_meta($product_ID, '_stock_status', 'instock', $unique);
     
     
      //Getting error on this line.
      $woocommerce->cart->add_to_cart( $product_ID, $quantity=1 );
     
    
     
    
     exit( wp_redirect( home_url( "cart" ) ) );
    }
    
    customcart();
      }

My html file

<form name="addpro" method="post" action="">
    <input type="submit" name="addcustomcarts" value="ADD TOO CART" />
  </form> 

Getting this error-->

Fatal error: Call to a member function add_to_cart() on a non-object in
C:\wamp\www\cutting-edge_server\wordpress_theme\wp-content\themes\cutting_age\responsive\functions.php on line 56

WooCommerce create new product and add to cart on form submit

I am customizing woo-commerce plugin to add product from the front end into the cart. I have written the function in functions.php, but i am getting a Fatal error.

Getting this error-->

Fatal error: Call to a member function add_to_cart() on a non-object in
C:\wamp\www\cutting-edge_server\wordpress_theme\wp-content\themes\cutting_age\responsive\functions.php on line 56

Any body have any idea how to resolve it?

My function.php file

if (isset($_POST["addcustomcarts"]))
        {
       echo $_SERVER[QUERY_STRING];
      // echo $_SERVER[REQUEST_URI];
        echo "i am in if";
        //exit();
    add_filter('woocommerce_before_cart', 'customcart');
    
    function customcart() { 
       echo "i am in function";
        
    //global $woocommerce;
    
    $my_post = array(
      'post_title'    => 'My post',
      'post_content'  => 'This is my post.',
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_type'     =>'product'
      
    );
    
    
    // Insert the post into the database
     $product_ID=wp_insert_post( $my_post );
     
     add_post_meta($product_ID, '_regular_price', 100, $unique);
     add_post_meta($product_ID, '_price', 100, $unique);
      add_post_meta($product_ID, '_stock_status', 'instock', $unique);
     
     
      //Getting error on this line.
      $woocommerce->cart->add_to_cart( $product_ID, $quantity=1 );
     
    
     
    
     exit( wp_redirect( home_url( "cart" ) ) );
    }
    
    customcart();
      }

My html file

<form name="addpro" method="post" action="">
    <input type="submit" name="addcustomcarts" value="ADD TOO CART" />
  </form> 
added 187 characters in body
Source Link
Sanjay Nakate
  • 211
  • 5
  • 11
  • 25

I am customizing woo-commerce plugin to add product from the front end into the cart. I have written the function in functions.php, but i am getting a Fatal error. Any body have any idea how to resolve it?

My function.php file

if (isset($_POST["addcustomcarts"]))
        {
       echo $_SERVER[QUERY_STRING];
      // echo $_SERVER[REQUEST_URI];
        echo "i am in if";
        //exit();
    add_filter('woocommerce_before_cart', 'customcart');
    
    function customcart() { 
       echo "i am in function";
        
    //global $woocommerce;
    
    $my_post = array(
      'post_title'    => 'My post',
      'post_content'  => 'This is my post.',
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_type'     =>'product'
      
    );
    
    
    // Insert the post into the database
     $product_ID=wp_insert_post( $my_post );
     
     add_post_meta($product_ID, '_regular_price', 100, $unique);
     add_post_meta($product_ID, '_price', 100, $unique);
      add_post_meta($product_ID, '_stock_status', 'instock', $unique);
     
     
      //Getting error on this line.
      $woocommerce->cart->add_to_cart( $product_ID, $quantity=1 );
     
    
     
    
     exit( wp_redirect( home_url( "cart" ) ) );
    }
    
    customcart();
      }

My html file

<form name="addpro" method="post" action="">
    <input type="submit" name="addcustomcarts" value="ADD TOO CART" />
  </form> 

Getting this error-->

Fatal error: Call to a member function add_to_cart() on a non-object in
C:\wamp\www\cutting-edge_server\wordpress_theme\wp-content\themes\cutting_age\responsive\functions.php on line 56

I am customizing woo-commerce plugin to add product from the front end into the cart. I have written the function in functions.php, but i am getting a Fatal error. Any body have any idea how to resolve it?

if (isset($_POST["addcustomcarts"]))
        {
       echo $_SERVER[QUERY_STRING];
      // echo $_SERVER[REQUEST_URI];
        echo "i am in if";
        //exit();
    add_filter('woocommerce_before_cart', 'customcart');
    
    function customcart() { 
       echo "i am in function";
        
    //global $woocommerce;
    
    $my_post = array(
      'post_title'    => 'My post',
      'post_content'  => 'This is my post.',
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_type'     =>'product'
      
    );
    
    
    // Insert the post into the database
     $product_ID=wp_insert_post( $my_post );
     
     add_post_meta($product_ID, '_regular_price', 100, $unique);
     add_post_meta($product_ID, '_price', 100, $unique);
      add_post_meta($product_ID, '_stock_status', 'instock', $unique);
     
     
      //Getting error on this line.
      $woocommerce->cart->add_to_cart( $product_ID, $quantity=1 );
     
    
     
    
     exit( wp_redirect( home_url( "cart" ) ) );
    }
    
    customcart();
      }

Getting this error-->

Fatal error: Call to a member function add_to_cart() on a non-object in
C:\wamp\www\cutting-edge_server\wordpress_theme\wp-content\themes\cutting_age\responsive\functions.php on line 56

I am customizing woo-commerce plugin to add product from the front end into the cart. I have written the function in functions.php, but i am getting a Fatal error. Any body have any idea how to resolve it?

My function.php file

if (isset($_POST["addcustomcarts"]))
        {
       echo $_SERVER[QUERY_STRING];
      // echo $_SERVER[REQUEST_URI];
        echo "i am in if";
        //exit();
    add_filter('woocommerce_before_cart', 'customcart');
    
    function customcart() { 
       echo "i am in function";
        
    //global $woocommerce;
    
    $my_post = array(
      'post_title'    => 'My post',
      'post_content'  => 'This is my post.',
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_type'     =>'product'
      
    );
    
    
    // Insert the post into the database
     $product_ID=wp_insert_post( $my_post );
     
     add_post_meta($product_ID, '_regular_price', 100, $unique);
     add_post_meta($product_ID, '_price', 100, $unique);
      add_post_meta($product_ID, '_stock_status', 'instock', $unique);
     
     
      //Getting error on this line.
      $woocommerce->cart->add_to_cart( $product_ID, $quantity=1 );
     
    
     
    
     exit( wp_redirect( home_url( "cart" ) ) );
    }
    
    customcart();
      }

My html file

<form name="addpro" method="post" action="">
    <input type="submit" name="addcustomcarts" value="ADD TOO CART" />
  </form> 

Getting this error-->

Fatal error: Call to a member function add_to_cart() on a non-object in
C:\wamp\www\cutting-edge_server\wordpress_theme\wp-content\themes\cutting_age\responsive\functions.php on line 56

blockquote
Source Link
helgatheviking
  • 14.5k
  • 8
  • 64
  • 115
Loading
edited tags
Link
Sanjay Nakate
  • 211
  • 5
  • 11
  • 25
Loading
Source Link
Sanjay Nakate
  • 211
  • 5
  • 11
  • 25
Loading