関数
Validation::inStock( int $post_id, string $sku, int $quant = 1 )
Returns GenericError
instance if the given item and quantity prevents adding to cart because of stock, true
otherwise
パラメータ パラメータ
- $post_id
(数値) (必須)
- $sku
(文字列) (必須) MUST be urlencoded
- $quant
(数値) (任意)
ファイル: src/API/Validation.php
public function inStock($post_id, $sku, $quant = 1) { global $usces; $quant = (int)$quant > 0 ? (int)$quant : 1; $sku_code = urldecode($sku); $stock = $usces->getItemZaikoNum($post_id, $sku_code); if (!isset($stocks[$post_id][$sku])) { if (!WCUtils::is_blank($stock)) { $stocks[$post_id][$sku] = $stock; } else { $stocks[$post_id][$sku] = null; } } $checkstock = $stocks[$post_id][$sku]; $stocks[$post_id][$sku] = $stocks[$post_id][$sku] - $quant; $itemRestriction = get_post_meta($post_id, '_itemRestriction', true); $itemOrderAcceptable = $usces->getItemOrderAcceptable($post_id); $post_status = get_post_status($post_id); if ( !$usces->is_item_zaiko($post_id, $sku_code) || ($itemOrderAcceptable != 1 && WCUtils::is_zero($stock)) || 'publish' != $post_status ) { return $this->master->estore->getErrorResponse(Store::ITEM_SOLD_OUT, [$sku], [$sku]); } if ( $quant > (int)$itemRestriction && !WCUtils::is_blank($itemRestriction) && !WCUtils::is_zero($itemRestriction) ) { return $this->master->estore->getErrorResponse( Store::PER_PURCHASE_LIMIT_EXCEEDED, [$itemRestriction, $sku], [$itemRestriction, $sku] ); } if ( $itemOrderAcceptable != 1 && 0 > $stocks[$post_id][$sku] && !WCUtils::is_blank($stock) ) { return $this->master->estore->getErrorResponse( Store::QUANT_EXCEEDS_STOCK_LIMIT, [$sku, $checkstock], [$sku, $checkstock] ); } return true; }