Welcart カートページの住所等の入力ページカスタマイズ


スポンサーリンク

Welcart カートページのカスタマイズは、結構見通しが悪い。
WelCartそのものの設計がやっぱり全然なってないとか、老年プログラマは思うのだった(笑)

それはおいといて・・・

カートページの入力は、メールアドレス部分、名前以降の部分にわかれている。

メールアドレス部分は、usc-shop/templates/cart/customer_info.php

住所の部分は、usc-shop/functions/template_func.php の function uesces_addressform

こういうのは、同じフォルダー/同じソースにまとめておくのがデバッグ効率がいいんだけど・・・

こういったところに初期のWELCARTは思い付きで作られているというのがわかる。

プラグインにしたってのは、絶対いいアイディアだと思うんだけどねぇ。

WelCartの致命傷は、とにかくプログラムの見通しが悪いってところだね。


Welcart カートページの住所等の入力 usces_filter_getShippingCharge フック関数で使える entry配列


以下 $entry[][] のキー名と内容例

reserve-pre_order_id:56ac3e594ee0c
reserve:Array
reserve-key:pre_order_id=56ac3e594ee0c
delivery-country:JP
delivery-pref:県名
delivery:Array
delivery-key:name1=テスト
delivery-key:name2=太郎
delivery-key:name3=テスト
delivery-key:name4=タロウ
delivery-key:zipcode=020-0000
delivery-key:address1=横浜市・・・
delivery-key:address2=3-24-555
delivery-key:address3=通販ビル4F
delivery-key:tel=1000-10-1000
delivery-key:fax=
delivery-key:country=JP
delivery-key:pref=県名
delivery-key:delivery_flag=0
delivery-key:mailaddress1=メールアドレス
delivery-key:mailaddress2=メールアドレス
customer-mailaddress1:メールアドレス
customer-name1:テスト
customer-name2:太郎
customer-name3:テスト
customer-name4:タロウ
customer-zipcode:020-0000
customer-pref:県名
customer-address1:横浜市・・・
customer-address2:3-24-555
customer-address3:通販ビル4F
customer-tel:1000-10-1000
customer-fax:
customer-key:mailaddress1=メールアドレス
customer-key:mailaddress2=メールアドレス
customer-key:password1=
customer-key:password2=
customer-key:name1=テスト
customer-key:name2=太郎
customer-key:name3=テスト
customer-key:name4=タロウ
customer-key:zipcode=020-0000
customer-key:address1=横浜市・・・
customer-key:address2=3-24-555
customer-key:address3=通販ビル4F
customer-key:tel=1000-10-1000
customer-key:fax=
customer-key:country=JP
customer-key:pref=県名
cart:Array
cart-key:0=Array
cart-key:1=Array
order-note:
order-delivery_method:0
order-delivery_date:指定できません
order-delivery_time:配達指定なし
order-payment_name:銀行振込
order-shipping_charge:1223
order-total_full_price:9475
condition:Array
item_total_price:
order-getpoint:0
order-usedpoint:
order-discount:0
order-shipping_charge:1223
order-cod_fee:0
order-tax:702
order-taio:
order-receipt:
order-admin:
order-key:usedpoint=
order-key:total_items_price=7550
order-key:discount=0
order-key:shipping_charge=1223
order-key:cod_fee=0
order-key:payment_name=銀行振込
order-key:delivery_method=0
order-key:delivery_date=指定できません
order-key:delivery_time=配達指定なし
order-key:total_full_price=9475
order-key:note=
order-key:tax=702
order-key:delidue_date=
order-key:cus_id=
order-key:total_price=8773
order-key:getpoint=0
means:
essential:
position:
value:
reserve-key:56ac3e594ee0c

phpの配列要素の表示のさせ方


if(is_array($entry['reserve'])) {
	foreach($entry['reserve'] as $k => $v) {
		fwrite($fp, "reserve-key:".$k."=".$v."\n"  );
	}
}

usces_filter_getShippingCharge フック関数で使える変数検査モジュール


もちろん、wp のフォルダーは書き込み許可にして trace.txt を一度作らせて、おくこと。
少なくとも、買い物かごの中身の取り出しは、usces_filter_getShippingCharge フック以外でも使える。
global $usces; が味噌だ。

add_filter( 'usces_filter_getShippingCharge', 'or_getShippingCharge', 10, 3);
function or_getShippingCharge($charge, $cart, $entry) {
	global $usces;
	$itemnumber = $usces->get_total_quantity( $cart ); // 合計個数
	$japcustompost = $entry['delivery']['pref']; // 配送先の県名
	$haisouhouhou  = $entry[‘order’][‘delivery_method’];

		//配送方法ID
		$d_method_id = $entry['order']['delivery_method'];
		//配送方法index
		//$d_method_index = $this->get_delivery_method_index($d_method_id);

$myfile = ABSPATH."trace.txt";
$fp = fopen($myfile, "w");
fwrite($fp, "合計個数:".$itemnumber."\n" );
fwrite($fp, "配送先県名:".$japcustompost."\n");
fwrite($fp, "配送方法:".$haisouhouhou."\n"  );
fwrite($fp, "配送ID:".$d_method_id."\n"  );

	// functions.php usces_get_cart_rows より抜粋
	global $usces_gp;
	$cart = $usces->cart->get_cart();
	$usces_gp = 0;
	$res = '';
	$itemNO=0;
	for($i=0; $i<count($cart); $i++) { 
		$cart_row = $cart[$i];
		$post_id  = $cart_row['post_id'];
		$sku      = $cart_row['sku'];
		$sku_code = esc_attr(urldecode($cart_row['sku']));
		$quantity = $cart_row['quantity'];
		$options  = $cart_row['options'];
		$advance  = $usces->cart->wc_serialize($cart_row['advance']);
		$itemCode = $usces->getItemCode($post_id);
		$itemName = $usces->getItemName($post_id);
		$cartItemName    = $usces->getCartItemName($post_id, $sku_code);
		$itemRestriction = $usces->getItemRestriction($post_id);
		$skuPrice        = $cart_row['price'];
		$skuZaikonum     = $usces->getItemZaikonum($post_id, $sku_code);
		$stockid         = $usces->getItemZaikoStatusId($post_id, $sku_code);
		$stock           = $usces->getItemZaiko($post_id, $sku_code);
		$red             = (in_array($stock, array(__('sellout','usces'), __('Out Of Stock','usces'), __('Out of print','usces')))) ? 'class="signal_red stock"' : 'class="stock"';
		$pictid = (int)$usces->get_mainpictid($itemCode);
$itemNO++;
fwrite($fp, "-----".$itemNO."-----\n"  );
fwrite($fp, "post_id:".$post_id."\n"  );
fwrite($fp, "sku:".$sku."\n"  );
fwrite($fp, "sku_code:".$sku_code."\n"  );
fwrite($fp, "quantity:".$quantity."\n"  );
fwrite($fp, "options:".$options."\n"  );
fwrite($fp, "advance:".$advance."\n"  );
fwrite($fp, "itemCode:".$itemCode."\n"  );
fwrite($fp, "itemName:".$itemName."\n"  );
fwrite($fp, "cartItemName:".$cartItemName."\n"  );
fwrite($fp, "itemRestriction:".$itemRestriction."\n"  );
fwrite($fp, "skuPrice:".$skuPrice."\n"  );
fwrite($fp, "skuZaikonum:".$skuZaikonum."\n"  );
fwrite($fp, "stockid:".$stockid."\n"  );
fwrite($fp, "stock:".$stock."\n"  );
fwrite($fp, "red:".$red."\n"  );
fwrite($fp, "pictid:".$pictid."\n"  );

		if ( empty($options) ) {
			$optstr =  '';
			$options =  array();
		}
		$optnNO=0;
		if( is_array($options) && count($options) > 0 ){
			$optstr = '';
			foreach($options as $key => $value){
				if( !empty($key) ) {
					$key = urldecode($key);
					if(is_array($value)) {
						$c = '';
						$optstr .= esc_html($key) . ' : '; 
						foreach($value as $v) {
							$optstr .= $c.nl2br(esc_html(urldecode($v)));
							$c = ', ';
						}
						$optstr .= "<br />\n"; 
					} else {
						$optstr .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))); 
					}
					$optnNO++;
					fwrite($fp, $optnNO.".options-key:".$key."=".$optstr."\n"  );

				}
			}
		}
	}
	fwrite($fp, "-----"."-----"."-----\n"  );
	
fwrite($fp, "reserve-pre_order_id:".$entry['reserve']['pre_order_id']."\n"  );
fwrite($fp, "reserve:".$entry['reserve']."\n"  );
if(is_array($entry['reserve'])) {
	foreach($entry['reserve'] as $k => $v) {
		fwrite($fp, "reserve-key:".$k."=".$v."\n"  );
	}
}

fwrite($fp, "delivery-country:".$entry['delivery']['country']."\n"  );
fwrite($fp, "delivery-pref:".$entry['delivery']['pref']."\n"  );
fwrite($fp, "delivery:".$entry['delivery']."\n"  );
if(is_array($entry['delivery'])) {
	foreach($entry['delivery'] as $k => $v) {
		fwrite($fp, "delivery-key:".$k."=".$v."\n"  );
	}
}

fwrite($fp, "customer-mailaddress1:".$entry['customer']['mailaddress1']."\n"  );
fwrite($fp, "customer-name1:".$entry['customer']['name1']."\n"  );
fwrite($fp, "customer-name2:".$entry['customer']['name2']."\n"  );
fwrite($fp, "customer-name3:".$entry['customer']['name3']."\n"  );
fwrite($fp, "customer-name4:".$entry['customer']['name4']."\n"  );
fwrite($fp, "customer-zipcode:".$entry['customer']['zipcode']."\n"  );
fwrite($fp, "customer-pref:".$entry['customer']['pref']."\n"  );
fwrite($fp, "customer-address1:".$entry['customer']['address1']."\n"  );
fwrite($fp, "customer-address2:".$entry['customer']['address2']."\n"  );
fwrite($fp, "customer-address3:".$entry['customer']['address3']."\n"  );
fwrite($fp, "customer-tel:".$entry['customer']['tel']."\n"  );
fwrite($fp, "customer-fax:".$entry['customer']['fax']."\n"  );
if(is_array($entry['customer'])) {
	foreach($entry['customer'] as $k => $v) {
		fwrite($fp, "customer-key:".$k."=".$v."\n"  );
	}
}


fwrite($fp, "cart:".$cart."\n"  );
if(is_array($cart)) {
	foreach($cart as $k => $v) {
		fwrite($fp, "cart-key:".$k."=".$v."\n"  );
	}
}


fwrite($fp, "order-note:".$entry['order']['note']."\n"  );
fwrite($fp, "order-delivery_method:".$entry['order']['delivery_method']."\n"  );
fwrite($fp, "order-delivery_date:".$entry['order']['delivery_date']."\n"  );
fwrite($fp, "order-delivery_time:".$entry['order']['delivery_time']."\n"  );
fwrite($fp, "order-payment_name:".$entry['order']['payment_name']."\n"  );
fwrite($fp, "order-shipping_charge:".$entry['order']['shipping_charge']."\n"  );
fwrite($fp, "order-total_full_price:".$entry['order']['total_full_price']."\n"  );

fwrite($fp, "condition:".$entry['condition']."\n"  );
fwrite($fp, "item_total_price:".$item_total_price."\n" );

fwrite($fp, "order-getpoint:".$entry['order']['getpoint']."\n"  );
fwrite($fp, "order-usedpoint:".$entry['order']['usedpoint']."\n"  );
fwrite($fp, "order-discount:".$entry['order']['discount']."\n"  );
fwrite($fp, "order-shipping_charge:".$entry['order']['shipping_charge']."\n"  );
fwrite($fp, "order-cod_fee:".$entry['order']['cod_fee']."\n"  );
fwrite($fp, "order-tax:".$entry['order']['tax']."\n"  );

fwrite($fp, "order-taio:".$entry['order']['taio']."\n"  );
fwrite($fp, "order-receipt:".$entry['order']['receipt']."\n"  );
fwrite($fp, "order-admin:".$entry['order']['admin']."\n"  );

if(is_array($entry['order'])) {
	foreach($entry['order'] as $k => $v) {
		fwrite($fp, "order-key:".$k."=".$v."\n"  );
	}
}


fwrite($fp, "means:".$entry['means']."\n"  );
fwrite($fp, "essential:".$entry['essential']."\n"  );
fwrite($fp, "position:".$entry['position']."\n"  );
fwrite($fp, "value:".$entry['value']."\n"  );
if(is_array($entry['value'])) {
	foreach($entry['value'] as $k => $v) {
		fwrite($fp, "value-key:".$k."=".$v."\n"  );
	}
}

if(is_array($entry['reserve'])) {
	foreach ( $entry['reserve'] as $key => $value ) {
		fwrite($fp, "reserve-key:".$value."\n"  );
	}
}

if(is_array($entry['custom_order'])) {
	foreach ( $entry['custom_order'] as $key => $value ) {
		fwrite($fp, "custom_order-key:".$value."\n"  );
	}
}

if(is_array($entry['custom_customer'])) {
	foreach ( $entry['custom_customer'] as $key => $value ) {
		fwrite($fp, "custom_customer-key:".$value."\n"  );
	}
}

if(is_array($entry['custom_delivery'])) {
	foreach ( $entry['custom_delivery'] as $key => $value ) {
		fwrite($fp, "custom_delivery-key:".$value."\n"  );
	}
}

fclose($fp);

	$charge = 1223;
	return $charge;

}

スポンサーリンク