2014-04-30 7 views
3
나는이 코드를 사용했습니다

어떻게 CSV

csv 파일에서 woocoommerce 약 1,000 쿠폰 코드를 가져 오기 위해 노력하고있어

에서 woocommerce 벌크 쿠폰을 가져올 수 있지만

이 코드 수를 작동하지 않습니다

당신이, 내가 오늘 솔루션을 필요로하시기 바랍니다 나에게 도움이 될

내가 CSV 파일의 각 행에 대해이 기능을 수행 할 필요
$coupon_code = 'UNIQUECODE'; // Code 
$amount = '10'; // Amount 
$discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product 
$coupon = array(
'post_title' => $coupon_code, 
'post_content' => '', 
'post_status' => 'publish', 
'post_author' => 1, 
'post_type' => 'shop_coupon' 
); 
$new_coupon_id = wp_insert_post($coupon); 
// Add meta 
update_post_meta($new_coupon_id, 'discount_type', $discount_type); 
update_post_meta($new_coupon_id, 'coupon_amount', $amount); 
update_post_meta($new_coupon_id, 'individual_use', 'no'); 
update_post_meta($new_coupon_id, 'product_ids', ''); 
update_post_meta($new_coupon_id, 'exclude_product_ids', ''); 
update_post_meta($new_coupon_id, 'usage_limit', ''); 
update_post_meta($new_coupon_id, 'expiry_date', ''); 
update_post_meta($new_coupon_id, 'apply_before_tax', 'yes'); 
update_post_meta($new_coupon_id, 'free_shipping', 'no'); 

: programmly 1 개 쿠폰을 생성합니다.

+0

에 의존 않습니다 - 어떻게 그렇다면? – Sol

답변

0

누군가가 여전히 답을 찾고 있다면 각 루프에 대해이 작업을 수행 할 수 있습니다. 나는 내 머리 꼭대기에서 정확한 기능을 알지 못하지만 단계는 매우 간단하며 Google이 도움을 줄 것입니다.

CSV를 배열로 가져 오기부터 시작하십시오. MySQL 쿼리와 매우 비슷합니다.

그런 다음 PHP foreach 루프를 수행합니다.

루프 내부에서 변수의 값을 채우는 코드를 사용합니다. 예를 들어,

$coupon_code = '$array[code]'; // Code 
$amount = '$array[amount]'; // Amount 
$discount_type = '$array[discount_type]'; 

당신은이 같은 메타 부분에 배열 데이터를 포함 할 수 있습니다 :

update_post_meta($new_coupon_id, 'product_ids', $array[ids]); 
update_post_meta($new_coupon_id, 'exclude_product_ids', $array[exclude]); 
update_post_meta($new_coupon_id, 'usage_limit', $array[limit]); 
update_post_meta($new_coupon_id, 'expiry_date', $array[expires]); 

가 다시이 iCode98이 무엇을 요구 할 수있는 기능을 단지 일반적인 개요입니다. PHP 매뉴얼은 훌륭한 정보를 가지고 있으며 csv를 배열로 바꾸고 각 루프에 대해 튜토리얼을 많이 제공합니다. 나는 이것에 대한 사용을 가지고 있을지도 모른다. 만약 내가 그것을 만들거나 누군가가 정말로 그것을 필요로한다면, 나는 이것을 실천적인 예제로 업데이트 할 것이다.

UPDATE :

이 작동 할 수 있어야하지만, 혹시이 문제를 해결 했 입력 파일

$file = fopen('myCSVFile.csv', 'r'); 
while (($line = fgetcsv($file)) !== FALSE) { 
    //$line is an array of the csv elements, This is where you would add the script above. 
    //Each column of the csv is in the array by id. So if you have: 
    //`a,b,c` Then `a=$line[0]` `b=$line[1]` `c=$line[2]` and so on. 
} 
fclose($file);