これは可能ですが、考慮する必要のある変数がたくさんあるため、まずは試してみることができます。 、
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)、予期している ')'。それを理解しようとしましたが、それを機能させることができませんでした。また、これらのサンプルオーダーに対して価格をゼロにする方法もあります。愚かな質問を申し訳ありません。私は未熟な逸脱者であり、私の頭を抱いているので。 – Sunny
私はコードを変更しました。テスト済みで動作しますが、貼り付けをコピーして終了するとは思わないので、製品id変数を変更し、選択した製品IDとアドレス変数を返すようにする必要があります。それで全部です。 –