많은 변수가 있으므로 고려해야 할 사항이 있으므로 먼저 시도하지 않으면 도움이되지 않습니다. ,
add_action('gform_after_submission', 'post_to_third_party', 10, 2);
function post_to_third_party($entry, $form) {
global $woocommerce;
// use this to find out $entry output
var_dump($entry);
// Make sure to add hidden field somewhere in the form with product id and define it here, If you have some other way of defining products in the form you need to make sure product id is returned in the variable below somehow
$product_id = rgar($entry, '12');
$address = array(
'first_name' => rgar($entry, '5'),
'last_name' => rgar($entry, '2'),
'company' => rgar($entry, '3'),
'email' => rgar($entry, '4'),
'phone' => rgar($entry, '5'),
'address_1' => rgar($entry, '6'),
'address_2' => rgar($entry, '7'),
'city' => rgar($entry, '8'),
'state' => rgar($entry, '9'),
'postcode' => rgar($entry, '10'),
'country' => rgar($entry, '11'),
);
$prices = array('totals' => array(
'subtotal' => 0,
'total' => 0,
));
$order = wc_create_order();
$order->add_product(wc_get_product($product_id), 1, $prices);
$order->set_address($address, 'billing');
$order->calculate_totals();
$order->update_status("processing", 'Sample Order', TRUE);
}
안녕 알리 프롬프트 응답을 주셔서 감사합니다 : 이것은 단지 시작하는 방법을 보여줍니다
, 당신은 나머지를 파악해야합니다. 함수 파일에 코드를 추가하고 테스트를 마쳤습니다. 아래 오류가 발생했습니다 구문 분석 오류 : 구문 오류, 예기치 않은 'last_name'(T_CONSTANT_ENCAPSED_STRING), 예상 ')'. 그것을 알아 내려고했지만 그것을 작동시키지 못했고 또한 어떻게이 샘플 주문에 대해 가격을 0으로 만들 수 있습니까? 어리석은 질문에 사과드립니다. 나는 미숙 한 편암가이며 내 머리를 쓰고 있습니다. – Sunny
코드를 변경 했으므로 테스트를 거쳤지만 작동하지만 붙여 넣기를 완료하지 않고 완료하면 제품 ID 변수를 변경하고 선택된 제품 ID를 반환하고 주소 변수를 제출하여 주소를 반환해야합니다. 그게 다야. –