0
제품을 프런트 엔드에서 장바구니에 추가하기 위해 우연한 상거래 플러그인을 사용자 정의하고 있습니다. functions.php에 함수를 작성했지만 치명적인 오류가 발생했습니다. 어떤 신체든지 그것을 해결하는 어떤 생각을 가지고 있습니까?치명적 오류 : function.php의 비 객체에서 add_to_cart() 멤버 함수를 호출하십시오.
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();
}
얻기이 오류 -> 치명적인 오류 : C의 비 객체의 멤버 함수 add_to_cart()를 호출 : \ WAMP \ WWW 절단 edge_server \ wordpress_theme \ WP - 콘텐츠 \ 테마 \ \ cutting_age \ responsive \ functions.php on line 56