2
wc_create_order를 사용하여 주문을 만들고 내 다운로드 섹션에 사용자가 다운로드 할 수있는 제품의 다운로드 링크를 가질 수 없다는 점을 제외하고는 모든 것이 좋습니다.WooCommerce 프로그래밍 방식으로 다운로드 가능한 제품 주문 만들기
$def_args = array('customer_id' => $user_id, 'status' => 'completed');
$order = wc_create_order($def_args);
$targs['totals']['subtotal'] = $ord['pay_amount'];
$targs['totals']['total'] = $ord['pay_amount'];
$targs['totals']['subtotal_tax'] = 0;
$targs['totals']['tax'] = 0;
$sku_ = $ord['sku'];
$order->add_product(get_product_by_sku($sku_) , 1, $targs); //(get_product with id and next is for quantity)
$order->set_address($address, 'billing');
$order->set_address($address, 'shipping');
$order->set_total($ord['pay_amount']);
$order->calculate_totals();
// I took get_product_by_sku function in stackoverflow but I don't remember which question.
function get_product_by_sku($sku) {
global $wpdb;
$product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku));
if ($product_id) return new WC_Product($product_id);
return null;
}
$ ord 변수에는 주문에 대한 정보가 있습니다.
다운로드 링크가있는 주문을하기 위해 함수 등을 호출해야합니까?