// output-stage empty guard, emitting an invalid node. Mirror the // guard already applied on the first-occurrence path below. if ( $attr_data_value !== '' ) { $xml_product[ $attr_attribute . "_$ca_extra" ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } } elseif ( in_array( $attr_attribute, self::SUFFIXED_REPEAT_TAGS, true ) && isset( Repeatable_Attributes::get_limits( (string) $feed->channel_hash )[ $attr_attribute ] ) ) { // Repeatable (#1213). Key by the row counter, not the source's last // segment: video sources are not numbered like images_N, and a static // value's mapfrom is the URL itself, which would make an invalid tag. if ( $attr_data_value !== '' ) { $xml_product[ $attr_attribute . "_$ga" ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } } else { $xml_product[ $attr_attribute . "_$ca_extra" ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } } elseif ( isset( $attr_data_value ) ) { if ( $attr_attribute == 'URL' || $attr_attribute == 'g:link' || $attr_attribute == 'link' || $attr_attribute == 'g:link_template' ) { if ( $product_data['product_type'] == 'variation' && preg_match( '/aelia_cs_currency/', $attr_value['suffix'] ) ) { $attr_value['suffix'] = str_replace( '?', '&', $attr_value['suffix'] ); $xml_product[ $attr_attribute ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } elseif ( $product_data['product_type'] == 'variation' && preg_match( '/currency/', $attr_value['suffix'] ) ) { $attr_value['suffix'] = str_replace( '?', '&', $attr_value['suffix'] ); $xml_product[ $attr_attribute ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } else { $xml_product[ $attr_attribute ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } } elseif ( ( $attr_attribute == 'g:image_link' || str_contains( $attr_attribute, 'g:additional_image_link' ) || $attr_attribute == 'image_link' ) && $attr_data_value !== '' ) { $xml_product[ $attr_attribute ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } elseif ( ( $attr_attribute == 'g:id' || $attr_attribute == 'id' || $attr_attribute == 'g:itemid' ) && $attr_data_value !== '' ) { $xml_product[ $attr_attribute ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } elseif ( $attr_attribute == 'g:item_group_id' && $attr_data_value !== '' ) { $xml_product[ $attr_attribute ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } elseif ( $attr_attribute == 'g:consumer_notice' && $attr_data_value !== '' ) { $xml_product[ $attr_attribute ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } elseif ( $attr_attribute == 'g:product_detail' && $attr_data_value !== '' ) { $xml_product[ $attr_attribute ] = "$attr_value[prefix]||" . $attr_map_from . '#' . $attr_data_value . "$attr_value[suffix]"; } elseif ( in_array( $attr_attribute, array( 'g:product_highlight', 'g:included_destination', 'g:excluded_destination' ), true ) && $attr_data_value !== '' ) { $xml_product[ $attr_attribute . "_$ga" ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } elseif ( $attr_data_value !== '' || ( ! $is_attr_static && in_array( $attr_map_from, self::ALWAYS_WRITTEN_FIELDS, true ) ) ) { $xml_product[ $attr_attribute ] = "$attr_value[prefix]" . $attr_data_value . "$attr_value[suffix]"; } } } } } } } } // Do we need to do some calculation on attributes for Google Shopping $xml_product = $this->woosea_calculate_value( $feed, $xml_product ); // The rewrite itself lives in Product_Feed_Helper, because a consumer that // has to predict these keys from the field mapping alone - the Parquet // writer resolves its column list before any product is assembled - must // apply exactly the same rule. foreach ( $xml_product as $key_product => $value_product ) { $stripped_key = Product_Feed_Helper::strip_mapped_attribute_prefix( $key_product ); if ( $stripped_key !== $key_product ) { unset( $xml_product[ $key_product ] ); $xml_product[ $stripped_key ] = $value_product; } } /** * Nested sub-attribute payload placement. * * For a migrated feed, resolved sub-attribute groups replace the legacy * marker string of their parent tag. Feed_Writer_XML then writes them as * nested elements, and Feed_Writer_JSONL encodes them as nested objects, * from one payload built once. * * This runs after woosea_calculate_value() and the attribute key rewrites, * and before `adt_product_feed_jsonl_product`, so that filter still sees * and can still override the final payload. CSV keeps the legacy * flattening, so its columns are unchanged. * * The two writers need different shapes. Feed_Writer_XML needs ordered * tag/value rows, because it writes elements. Feed_Writer_JSONL encodes * the payload as-is, so it needs one flat object per group. * * @since 13.5.8 */ if ( in_array( $file_format, self::NESTED_PAYLOAD_FORMATS, true ) && Feed_Writer_XML::uses_new_writer( $feed, $feed_channel ) ) { $xml_product = Sub_Attribute_Resolver::apply_to_payload( $xml_product, $product_data, $feed, 'xml' === $file_format ? Sub_Attribute_Resolver::SHAPE_ROWS : Sub_Attribute_Resolver::SHAPE_OBJECT ); } // For Skroutz template if ( $feed_channel['fields'] == 'skroutz' ) { if ( $product->get_type() == 'variation' ) { $product_id = $product->get_parent_id(); $xml_piece[ $product_id ]['skroutz_variations'][] = $xml_product; ++$exclusion_counts['nested_variation']; } else { // The catalogue is walked newest first, so the variations of this // product are usually collected before the product row itself. // Carry them over, else this assignment discards them. // // Variations collected in an earlier batch are seeded back into // $xml_piece at the start of this one, so this covers the // cross-batch case too. if ( isset( $xml_piece[ $product->get_id() ]['skroutz_variations'] ) ) { $xml_product['skroutz_variations'] = $xml_piece[ $product->get_id() ]['skroutz_variations']; } $xml_piece[ $product->get_id() ] = $xml_product; } } else { // For JSONL formats, allow channel-specific product-level transformations // (e.g. shipping parsing and HTML entity decoding for OpenAI). if ( in_array( $file_format, self::STRUCTURED_PAYLOAD_FORMATS, true ) ) { /** * Filter a single JSONL product array before it is added to the batch. * * Parquet consumes the same payload, because the shape this filter * produces is the typed one: real booleans, lists as arrays and * nested objects as arrays. The filter keeps its JSONL name so the * channel modules already hooked to it keep working unchanged. * * @since 13.5.2 * * @param array $xml_product The product data key/value array. * @param array $feed_channel The active channel configuration. * @param object $feed The feed object. */ $xml_product = apply_filters( 'adt_product_feed_jsonl_product', $xml_product, $feed_channel, $feed ); } elseif ( 'xml' === $file_format ) { /** * Filter a single XML product array before it is added to the batch. * * Mirrors `adt_product_feed_jsonl_product` for the XML format so * channel modules can inject attributes that are not part of the * merchant's field mapping (e.g. UCP `g:native_commerce`). * * @since 13.5.8 * * @param array $xml_product The product data key/value array. * @param array $feed_channel The active channel configuration. * @param object $feed The feed object. * @param object $product The WooCommerce product object. */ $xml_product = apply_filters( 'adt_product_feed_xml_product', $xml_product, $feed_channel, $feed, $product ); } $xml_piece[] = $xml_product; } unset( $xml_product ); unset( $product_data ); } endwhile; // The rows the query returned. The Expected vs Actual report compares them with // products_count, so a product the query never returned is still accounted for. $exclusion_counts['walked'] = ( $exclusion_counts['walked'] ?? 0 ) + $prods->post_count; wp_reset_query(); wp_reset_postdata(); // Advance the cursor to the last row this query walked. The query itself only // selected IDs, so the sort key of that one row is read here - a single read // per batch, not per product. // // In practice this is a cache hit rather than a query: the row loop above ran // wc_get_product() on this same ID, which primes WP's post cache. That is an // optimisation, not a requirement - if the cache is ever cold the worst case is // one extra single-row lookup per batch. if ( $batch_last_id > 0 ) { $batch_last_date = get_post_field( 'post_date', $batch_last_id, 'raw' ); if ( ! empty( $batch_last_date ) ) { $batch_cursor = array( 'date' => $batch_last_date, 'id' => $batch_last_id, ); } } // Add processed products to array // if(get_option('woosea_duplicates')){ // update_option($channel_duplicates, $prevent_duplicates, 'no'); // } // Skroutz: an entry that holds nothing but collected variations has no product row // behind it. Either the parent falls in a later batch, or it is filtered out of the // feed altogether. It is not a product, so it must never reach the writer - that // would emit a node containing only . Hold it for the next batch, where // the parent either arrives and claims it or it is dropped when the run ends. $pending_variations = array(); if ( 'skroutz' === $feed_channel['fields'] && is_array( $xml_piece ) ) { foreach ( $xml_piece as $piece_key => $piece_value ) { if ( is_array( $piece_value ) && array( 'skroutz_variations' ) === array_keys( $piece_value ) ) { $pending_variations[ (int) $piece_key ] = $piece_value['skroutz_variations']; unset( $xml_piece[ $piece_key ] ); } } /** * Maximum number of parent products whose variations are carried to the next batch. * * The carry-over is written to feed meta after every batch. A catalogue that * excludes many variable parents while including their variations would grow it * without limit, so it is capped. Oldest entries are dropped first. * * @since 13.5.8 * * @param int $max Maximum number of parent products to carry over. */ $max_pending = (int) apply_filters( 'woosea_skroutz_max_pending_variation_parents', 500 ); if ( $max_pending > 0 && count( $pending_variations ) > $max_pending ) { $pending_variations = array_slice( $pending_variations, -$max_pending, null, true ); } } /** * Write row to CSV/TXT or XML or JSONL file */ if ( in_array( $file_format, self::STRUCTURED_PAYLOAD_FORMATS, true ) && is_array( $xml_piece ) && ! empty( $xml_piece ) ) { $file = $this->get_structured_payload_writer( $file_format )->write_feed( array_filter( $xml_piece ), $feed, false ); unset( $xml_piece ); } elseif ( $file_format != 'xml' && is_array( $products ) && ! empty( $products ) ) { $file = $this->woosea_create_csvtxt_feed( array_filter( $products ), $feed, 'false' ); } else { if ( is_array( $xml_piece ) && $file_format === 'xml' ) { $file = $this->woosea_create_xml_feed( array_filter( $xml_piece ), $feed, 'false' ); unset( $xml_piece ); } unset( $products ); } // Hand the resume point to the next batch of this run. The unattached Skroutz // variations travel with it, because they are only meaningful against the batch // that follows this one. $feed->batch_cursor = $batch_cursor; $feed->batch_pending_variations = $pending_variations; $feed->save(); /** * Ready creating file, clean up our feed configuration mess now */ delete_option( 'attributes_dropdown' ); delete_option( 'channel_attributes' ); return $exclusion_counts; } /** * Calculate the value of an attribute */ public function woosea_calculate_value( $feed, $xml_product ) { $feed_channel = $feed->channel; $feed_attributes = $feed->attributes; /** * Filter the feed attributes before processing. * * @since 13.5.0 * @param array $feed_attributes The feed attributes array. * @return array */ $feed_attributes = apply_filters( 'adt_feed_get_attributes', $feed_attributes ); if ( empty( $feed_channel ) || empty( $feed_attributes ) ) { return $xml_product; } // trim whitespaces from attribute values $xml_product = array_map( 'trim', $xml_product ); // Check if we need to 'calculate' the identifier_exists attribute value. // The helper call below further gates on the feed actually having identifier_exists // mapped to Plugin Calculation, so this runs for any channel that configured it. // Some channels (e.g. Facebook DRM) emit these keys without the g: namespace prefix, // so we accept both naming conventions here. if ( isset( $xml_product['g:condition'] ) && ! isset( $xml_product['g:identifier_exists'] ) && ! isset( $xml_product['identifier_exists'] ) ) { $identifier_exists = 'no'; // default value is no // Per Google's requirements, we only need identifier_exists if the product is new if ( strtolower( $xml_product['g:condition'] ) === 'new' ) { $brand = $xml_product['g:brand'] ?? $xml_product['brand'] ?? ''; $gtin = $xml_product['g:gtin'] ?? $xml_product['gtin'] ?? ''; $mpn = $xml_product['g:mpn'] ?? $xml_product['mpn'] ?? ''; if ( '' !== $brand && ( '' !== $gtin || '' !== $mpn ) ) { $identifier_exists = 'yes'; } } // Only add identifier_exists to the feed if it's configured as a Plugin Calculation, // and use whichever attribute name the channel declares (g:identifier_exists or identifier_exists). $identifier_exists_attribute = $this->get_calculated_identifier_exists_attribute( $feed_attributes ); if ( null !== $identifier_exists_attribute ) { $xml_product[ $identifier_exists_attribute ] = $identifier_exists; } } if ( $feed_channel['name'] == 'Mall.sk' ) { $has_calculated_attribute = false; foreach ($feed_attributes as $attr) { if (isset($attr['mapfrom']) && $attr['mapfrom'] === 'calculated') { $has_calculated_attribute = true; break; } } if ($has_calculated_attribute) { $xml_product['VARIABLE_PARAMS'] = 'calculated'; } } return $xml_product; } /** * Get the configured identifier_exists attribute name when it is mapped to Plugin Calculation. * * Some channels (e.g. Google Shopping) use the 'g:identifier_exists' name while others * (e.g. Facebook DRM) use the bare 'identifier_exists' name. Returns whichever variant is * configured on the feed, or null if no Plugin Calculation mapping exists for it. * * @param array $feed_attributes Feed attribute definitions. * @return string|null The configured attribute name or null when not set to Plugin Calculation. */ private function get_calculated_identifier_exists_attribute( $feed_attributes ) { $identifier_exists_attributes = array( 'g:identifier_exists', 'identifier_exists' ); foreach ( $feed_attributes as $attr ) { if ( ! isset( $attr['attribute'], $attr['mapfrom'] ) ) { continue; } if ( 'calculated' === $attr['mapfrom'] && in_array( $attr['attribute'], $identifier_exists_attributes, true ) ) { return $attr['attribute']; } } return null; } /** * Make start and end sale date readable */ public function get_sale_date( $id, $name ) { $date = $this->get_attribute_value( $id, $name ); if ( $date ) { if ( is_int( $date ) ) { return date( 'Y-m-d', $date ); } } return false; } /** * Get product stock */ public function get_stock( $id ) { $status = $this->get_attribute_value( $id, '_stock_status' ); if ( $status ) { if ( $status == 'instock' ) { return 'in stock'; } elseif ( $status == 'outofstock' ) { return 'out of stock'; } } return 'out of stock'; } /** * Create proper format image URL's */ public function get_image_url( $image_url = '' ) { if ( ! empty( $image_url ) ) { if ( substr( trim( $image_url ), 0, 4 ) === 'http' || substr( trim( $image_url ), 0, 5 ) === 'https' || substr( trim( $image_url ), 0, 3 ) === 'ftp' || substr( trim( $image_url ), 0, 4 ) === 'sftp' ) { return rtrim( $image_url, '/' ); } else { $base = get_site_url(); $image_url = $base . $image_url; return rtrim( $image_url, '/' ); } } return $image_url; } /** * Get attribute value */ public function get_attribute_value( $id, $name ) { if ( str_contains( $name, 'attribute_pa' ) ) { $taxonomy = str_replace( 'attribute_', '', $name ); $meta = get_post_meta( $id, $name, true ); $term = get_term_by( 'slug', $meta, $taxonomy ); return $term->name; } else { return get_post_meta( $id, $name, true ); } } /** * Execute category taxonomy mappings */ private function woocommerce_sea_mappings( $project_mappings, $product_data ) { $original_cat = $product_data['categories']; $original_cat = preg_replace( '/&/', '&', $original_cat ); $original_cat = preg_replace( '/>/', '>', $original_cat ); $original_cat = ltrim( $original_cat, '||' ); $tmp_cat = ''; $match = 'false'; /** * The Category Mapping tab writes a row per product category, so one save of the tab * persists a row for every category, blank "map to category" included. A table where * no row carries a value says nothing about any product, so treat it the same as an * empty tab and leave the mapped value alone instead of clearing it. */ $table_has_value = (bool) array_filter( array_column( $project_mappings, 'map_to_category' ) ); // The product's own category term ids do not change between mapping rows. $prod_id_cat = $product_data['id']; if ( ( $product_data['product_type'] ?? '' ) == 'variation' ) { $prod_id_cat = $product_data['item_group_id'] ?? $product_data['id']; } // Cast both sides so the term id match below stays strict. Mapping rows keep their ids as strings. $product_cats_ids = array_map( 'absint', wc_get_product_term_ids( $prod_id_cat, 'product_cat' ) ); foreach ( $project_mappings as $pm_key => $pm_array ) { // Strip slashes $pm_array['criteria'] = str_replace( '\\', '', $pm_array['criteria'] ); $pm_array['criteria'] = str_replace( '/', '', $pm_array['criteria'] ); $pm_array['criteria'] = trim( $pm_array['criteria'] ); $original_cat = str_replace( '\\', '', $original_cat ); $original_cat = str_replace( '/', '', $original_cat ); $original_cat = trim( $original_cat ); // First check if there is a category mapping for this specific product if ( ( preg_match( '/' . $pm_array['criteria'] . '/', $original_cat ) ) ) { if ( ! empty( $pm_array['map_to_category'] ) && in_array( absint( $pm_array['categoryId'] ?? 0 ), $product_cats_ids, true ) ) { $category_pieces = explode( '-', $pm_array['map_to_category'] ); $tmp_cat = $category_pieces[0]; $match = 'true'; } } elseif ( $pm_array['criteria'] == $original_cat ) { // Guard the value: an empty row must not blank the product through $tmp_cat. if ( ! empty( $pm_array['map_to_category'] ) ) { $category_pieces = explode( '-', $pm_array['map_to_category'] ); $tmp_cat = $category_pieces[0]; $match = 'true'; } } else { // Do nothing } } if ( $match == 'true' ) { if ( array_key_exists( 'id', $product_data ) ) { // Decode until stable so a stored entity (e.g. &, or &amp;) is not escaped again on output. do { $prev_cat = $tmp_cat; $tmp_cat = html_entity_decode( $tmp_cat, ENT_QUOTES | ENT_HTML5, 'UTF-8' ); } while ( $tmp_cat !== $prev_cat ); $product_data['categories'] = $tmp_cat; } } elseif ( $table_has_value ) { // No mapping found so make google_product_category empty $product_data['categories'] = ''; } return $product_data; } /** * Function to exclude products based on individual product exclusions */ private function woosea_exclude_individual( $product_data ) { $allowed = 1; // Check if product was already excluded from the feed $product_excluded = ucfirst( get_post_meta( $product_data['id'], '_woosea_exclude_product', true ) ); if ( $product_excluded == 'Yes' ) { $allowed = 0; } if ( $allowed < 1 ) { $product_data = array(); $product_data = null; } else { return $product_data; } } /** * Do analysis of product data for Google Shopping */ private function woosea_gs_analysis( $project, $product_data ) { $gs_analysis_check = array(); $gs_analysis_check['project_hash'] = $project['project_hash']; $gs_analysis_check['project_hash']['timestamp'] = 'llqlql'; // Check title criteria $length_title = strlen( $product_data['title'] ); $gs_analysis_check['project_hash'][ $product_data['id'] ]['title']['length'] = $length_title; $gs_analysis_check['project_hash'][ $product_data['id'] ]['title']['more_information'] = 'https://support.google.com/merchants/answer/6324415'; if ( $length_title > 150 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['title']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['title']['notification'] = "Your title / product name is too long ($length_title characters), it has been truncated to 150 characters in order to meet Google's criteria."; } elseif ( $length_title < 64 and $length_title > 0 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['title']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['title']['notification'] = "Your title / product name is too short ($length_title characters), make sure it is over 64 characters long. Best practice is to use all 150 characters. Include the important details that define your product."; } elseif ( $length_title < 1 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['title']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['title']['notification'] = 'Your title / product name is empty, make sure it is over 64 characters long. Best practice is to use all 150 characters. Include the important details that define your product.'; } else { $gs_analysis_check[ $product_data['project_hash']['id'] ]['title']['passed_check'] = 'yes'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['title']['notification'] = 'The length of your title / product name is perfect, well done!'; } // Check description criteria $length_description = strlen( $product_data['description'] ); $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['length'] = $length_description; $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['more_information'] = 'https://support.google.com/merchants/answer/6324468'; if ( $length_description > 5000 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['notification'] = "Your product description is too long ($length_description characters), make sure your product description is no longer than 5000 characters."; } elseif ( $length_description < 160 and $length_description > 0 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['notification'] = "Your product description is too short ($length_description characters), make sure to list the most important details in the first 160 - 500 characters."; } elseif ( $length_description < 1 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['notification'] = 'Your product description is empty, make sure to list the most important details in the first 160 - 500 characters.'; } else { $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['passed_check'] = 'yes'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['description']['notification'] = 'The length of your title / product name is perfect, well done!'; } // Check availability $gs_analysis_check[ $product_data['project_hash']['id'] ]['availability']['more_information'] = 'https://support.google.com/merchants/answer/6324448'; $availability_allowed = array( 'in_stock', 'out_of_stock', 'preorder', 'backorder' ); $availability = $product_data['availability']; if ( ! in_array( $product_data['availability'], $availability_allowed ) ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['availability']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['availability']['notification'] = "Your availability value ($availability) does not meet Google's requirements (make sure the value is in_stock, out_of_stock, preorder or backorder)."; } else { $gs_analysis_check[ $product_data['project_hash']['id'] ]['availability']['passed_check'] = 'yes'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['availability']['notification'] = "Your availability value ($availability) meets Google's requirements, well done!"; } // Check link $length_link = strlen( $product_data['link'] ); $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['length'] = $length_link; $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['more_information'] = 'https://support.google.com/merchants/answer/6324416'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['passed_check'] = 'yes'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['notification'] = "Your product link (URL) meets Google's requirements."; if ( $length_link > 2000 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['notification'] = "Your product link (URL) is too long ($length_link characters), make sure the product link (URL) is no longer than 2000 characters."; } elseif ( $length_link < 1 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['notification'] = 'Your product link (URL) is empty.'; } else { } if ( ! filter_var( $product_data['link'], FILTER_VALIDATE_URL ) !== false ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['notification'] = "Your product link (URL) doesn't appear to be a valid URL."; } $url = parse_url( $product_data['link'] ); $allowed_schema = array( 'http', 'https' ); if ( ! in_array( $url['scheme'], $allowed_schema ) ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['link']['notification'] = "Your product link (URL) doesn't http or https, which is required by Google."; } // Check price $length_price = strlen( $product_data['price'] ); $product_price = $product_data['price']; $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['length'] = $length_price; $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['more_information'] = 'https://support.google.com/merchants/answer/6324371'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['passed_check'] = 'yes'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['notification'] = "Your product price ($product_price) meets Google's requirements."; if ( $length_price < 1 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['notification'] = 'Your product price is empty, make sure to add a price to all your products.'; } $separator = wc_get_price_decimal_separator(); if ( $separator == '.' ) { if ( ! is_numeric( $product_data['price'] ) ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['notification'] = "Your product price ($product_price) doesn't appear to be a valid price."; } } if ( empty( $product_data['price'] ) ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['notification'] = "Your product price ($product_price) doesn't appear to be a valid price, it cannot be empty of 0 (zero)"; } if ( $product_data['price'] == '0,00' ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['price']['notification'] = "Your product price ($product_price) doesn't appear to be a valid price, it cannot be empty of 0 (zero)"; } // Product type $length_product_type = strlen( $product_data['product_type'] ); $product_type = $product_data['product_type']; $gs_analysis_check[ $product_data['project_hash']['id'] ]['product_type']['length'] = $length_price; $gs_analysis_check[ $product_data['project_hash']['id'] ]['product_type']['more_information'] = 'https://support.google.com/merchants/answer/6324406'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['product_type']['passed_check'] = 'yes'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['product_type']['notification'] = "Your product type meets Google's requirements."; if ( $length_product_type > 750 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['product_type']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['product_type']['notification'] = 'Your product type value is too long, make sure it is no longer than 750 characters.'; } elseif ( $length_product_type < 1 ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['product_type']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['product_type']['notification'] = 'Your product type field is empty.'; } else { } // Condition $gs_analysis_check[ $product_data['project_hash']['id'] ]['condition']['more_information'] = 'https://support.google.com/merchants/answer/6324469'; $condition_allowed = array( 'new', 'refurbished', 'used', 'New', 'Refurbished', 'Used' ); $condition = $product_data['condition']; if ( ! in_array( $product_data['condition'], $condition_allowed ) ) { $gs_analysis_check[ $product_data['project_hash']['id'] ]['condition']['passed_check'] = 'no'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['condition']['notification'] = "Your condition value ($condition) does not meet Google's requirements (make sure the value is new, refurbished or used)."; } else { $gs_analysis_check[ $product_data['project_hash']['id'] ]['condition']['passed_check'] = 'yes'; $gs_analysis_check[ $product_data['project_hash']['id'] ]['condition']['notification'] = "Your condition value ($condition) meets Google's requirements, well done!"; } // Save Google Shopping analysis results update_option( 'woosea_gs_analysis_results', $gs_analysis_check, false ); } /** * Get comma separated categories * * @param array $category_ids The category IDs. * @return string The comma separated categories. */ private function get_comma_separated_categories( $category_ids ) { $categories_comma_separated = array(); // Build category hierarchy map $categories_by_parent = array(); $all_categories = array(); foreach ( $category_ids as $category_id ) { $category = get_term( $category_id, 'product_cat' ); if ( ! is_wp_error( $category ) ) { $all_categories[ $category_id ] = $category; $parent_id = $category->parent; if ( ! isset( $categories_by_parent[ $parent_id ] ) ) { $categories_by_parent[ $parent_id ] = array(); } $categories_by_parent[ $parent_id ][] = $category_id; } } // Recursive function to add categories in hierarchical order $add_categories_hierarchically = function( $parent_id, $categories_by_parent, $all_categories, &$result ) use ( &$add_categories_hierarchically ) { if ( ! isset( $categories_by_parent[ $parent_id ] ) ) { return; } foreach ( $categories_by_parent[ $parent_id ] as $category_id ) { if ( isset( $all_categories[ $category_id ] ) ) { $result[] = $all_categories[ $category_id ]->name; // Recursively add children of this category $add_categories_hierarchically( $category_id, $categories_by_parent, $all_categories, $result ); } } }; // Start with root categories (parent = 0) and build hierarchically $add_categories_hierarchically( 0, $categories_by_parent, $all_categories, $categories_comma_separated ); return implode( ',', $categories_comma_separated ); } }
Warning: Cannot modify header information - headers already sent by (output started at /home/eternalzen/public_html/wp-content/plugins/woo-product-feed-pro/classes/class-get-products.php:1) in /home/eternalzen/public_html/wp-includes/feed-rss2-comments.php on line 8
Comments on: Pink Opal & White Jade Mala Bracelet https://www.eternal-zen.com/product/pink-opal-white-jade-mala-gemstone-bracelet/ Handmade mala necklaces and bracelets, crystal healing, meditation, self care needs Thu, 03 Mar 2022 00:19:56 +0000 hourly 1