public function getProductVariations($post_id) { // update cache if required if (!array_key_exists($post_id, $this->product_variations)) { $this->product_variations[$post_id] = WPLA_ProductWrapper::getVariations($post_id); } return $this->product_variations[$post_id]; }
public function updateCustomListingTitle($post_id) { // get custom listing title $custom_title = get_post_meta($post_id, '_amazon_title', true); // if ( ! $custom_title ) return; // disabled to update title when post_title changed // get product $product = get_product($post_id); if (!$product) { return; } // use post_title if no custom title found if (empty($custom_title)) { $custom_title = $product->post->post_title; } // update simple listing or parent variation $data = array('listing_title' => $custom_title); $this->updateWhere(array('post_id' => $post_id), $data); // update variable listings if ($product->product_type == 'variable') { // get variations $variations = WPLA_ProductWrapper::getVariations($post_id); // process variations (childs) foreach ($variations as $var) { // get variation product data $variation_id = $var['post_id']; $variation_attributes = $var['variation_attributes']; // generate title suffix from attribute values $attribute_values = array_values($variation_attributes); $suffix = join(', ', $attribute_values); // update variation listing title - and attributes $data = array(); $data['listing_title'] = $custom_title . ', ' . $suffix; $data['vattributes'] = serialize($variation_attributes); $this->updateWhere(array('post_id' => $variation_id), $data); } } // if variable }
function getProductVariations($post_id) { // update cache if required if ($this->last_product_var_id != $post_id) { $this->last_product_variations = WPLA_ProductWrapper::getVariations($post_id); $this->last_product_var_id = $post_id; } return $this->last_product_variations; }