// SUBSTITUA OS MÉTODOS register_feed_endpoint() e generate_feed() POR ESTAS VERSÕES CORRIGIDAS:
public function register_feed_endpoint() {
// Registrar o endpoint personalizado
add_rewrite_rule('^google-shopping-feed\.xml$', 'index.php?gsf_feed=1', 'top');
// Adicionar variável de query
add_filter('query_vars', array($this, 'add_query_vars'));
// Hook alternativo para capturar a requisição mais cedo
add_action('template_redirect', array($this, 'handle_feed_request'));
}
public function add_query_vars($vars) {
$vars[] = 'gsf_feed';
return $vars;
}
// MÉTODO ALTERNATIVO PARA CAPTURAR A REQUISIÇÃO
public function handle_feed_request() {
global $wp_query;
// Verificar se é uma requisição para o feed
if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], 'google-shopping-feed.xml') !== false) {
$this->output_feed();
exit;
}
// Método alternativo usando query vars
if (get_query_var('gsf_feed')) {
$this->output_feed();
exit;
}
}
// MÉTODO PRINCIPAL PARA GERAR O FEED
public function output_feed() {
if (!class_exists('WooCommerce')) {
wp_die('WooCommerce is required');
}
// Limpar qualquer saída anterior
while (ob_get_level() > 0) {
ob_end_clean();
}
// Definir headers corretos
header('Content-Type: application/xml; charset=UTF-8');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
$settings = get_option('gsf_settings', array());
echo '' . "\n";
echo '' . esc_url(home_url()) . '' . "\n";
echo '' . "\n";
// DEBUG DETALHADO
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
// Query simples para produtos
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 10 // Limitar para teste
);
$products_query = new WP_Query($args);
echo '' . "\n";
$processed_count = 0;
$skipped_count = 0;
if ($products_query->have_posts()) {
while ($products_query->have_posts()) {
$products_query->the_post();
$product_id = get_the_ID();
$product = wc_get_product($product_id);
echo '' . "\n";
if (!$product) {
$skipped_count++;
echo '' . "\n";
continue;
}
$processed_count++;
echo '- ' . "\n";
// ID do produto
echo '' . $product->get_id() . '' . "\n";
// Título
$title = $product->get_name();
echo '' . "\n";
// LINK DO PRODUTO (CORRIGIDO)
$product_link = get_permalink($product_id);
echo '' . "\n";
// DESCRIÇÃO SEM LIMITE
$description = $product->get_description();
if (empty($description)) {
$description = $product->get_short_description();
}
if (empty($description)) {
$description = $product->get_name();
}
$description = wp_strip_all_tags($description);
$description = html_entity_decode($description, ENT_QUOTES, 'UTF-8');
echo '' . "\n";
// Preço
$price = $product->get_price();
if (!empty($price)) {
// Aplicar desconto se configurado
if (isset($settings['discount_percentage']) && $settings['discount_percentage'] > 0) {
$discount = $settings['discount_percentage'] / 100;
$price = $price * (1 - $discount);
}
$currency = isset($settings['currency']) ? $settings['currency'] : 'BRL';
echo '' . number_format($price, 2, '.', '') . ' ' . $currency . '' . "\n";
}
// Disponibilidade
$availability = $product->is_in_stock() ? 'in stock' : 'out of stock';
echo '' . $availability . '' . "\n";
// Condição
echo 'new' . "\n";
// Marca
$brand = isset($settings['default_brand']) ? $settings['default_brand'] : get_bloginfo('name');
echo '' . "\n";
// CATEGORIA LIMPA (SEM "TODOS OS PRODUTOS")
$terms = get_the_terms($product_id, 'product_cat');
if ($terms && !is_wp_error($terms)) {
$categories = array();
foreach ($terms as $term) {
if (strtolower($term->name) !== 'todos os produtos' &&
strtolower($term->name) !== 'all products' &&
$term->slug !== 'uncategorized') {
$categories[] = $term->name;
}
}
if (!empty($categories)) {
echo ' ', $categories) . ']]>' . "\n";
} else {
$default_type = isset($settings['product_type']) ? $settings['product_type'] : 'Cosmetics';
echo '' . "\n";
}
}
// Google Product Category
$google_category = isset($settings['default_google_category']) ? $settings['default_google_category'] : '469';
echo '' . $google_category . '' . "\n";
// IMAGEM PRINCIPAL
$image_id = $product->get_image_id();
if ($image_id) {
$image_url = wp_get_attachment_image_url($image_id, 'full');
if ($image_url) {
echo '' . "\n";
}
} else {
echo '' . "\n";
}
// IMAGENS ADICIONAIS
$attachment_ids = $product->get_gallery_image_ids();
foreach ($attachment_ids as $attachment_id) {
$image_url = wp_get_attachment_image_url($attachment_id, 'full');
if ($image_url) {
echo '' . "\n";
}
}
// GTIN
$gtin = get_post_meta($product_id, '_gsf_gtin', true);
if (!empty($gtin)) {
echo '' . $gtin . '' . "\n";
}
// MPN
$mpn_source = isset($settings['mpn_source']) ? $settings['mpn_source'] : 'null';
if ($mpn_source === 'sku') {
$mpn = $product->get_sku();
if (!empty($mpn)) {
echo '' . "\n";
}
} elseif ($mpn_source === 'id') {
echo '' . $product_id . '' . "\n";
} elseif ($mpn_source === 'custom' && !empty($settings['default_mpn'])) {
echo '' . "\n";
}
// Identifier exists
$identifier_exists = isset($settings['identifier_exists']) ? $settings['identifier_exists'] : 'yes';
if (!empty($identifier_exists)) {
echo '' . $identifier_exists . '' . "\n";
}
// Is bundle
$is_bundle = isset($settings['is_bundle']) ? $settings['is_bundle'] : 'no';
echo '' . $is_bundle . '' . "\n";
// CHECKOUT LINK (CORRIGIDO)
$checkout_template = isset($settings['checkout_link_template']) ?
$settings['checkout_link_template'] :
'https://kinzancosmeticos.com/finalizar-compra-2/?&add-to-cart={product_id}';
if (!empty($checkout_template)) {
$checkout_link = str_replace('{product_id}', $product_id, $checkout_template);
echo '' . "\n";
}
echo '
' . "\n";
// Limitar para teste inicial
if ($processed_count >= 5) {
echo '' . "\n";
break;
}
}
} else {
echo '' . "\n";
}
wp_reset_postdata();
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
}
// REMOVER O MÉTODO generate_feed() ANTIGO COMPLETAMENTE
// O método output_feed() substitui ele completamente
public function activate() {
$this->register_feed_endpoint();
flush_rewrite_rules();
}
public function deactivate() {
flush_rewrite_rules();
}
// INSTRUÇÕES DE IMPLEMENTAÇÃO:
/*
1. Substitua os métodos register_feed_endpoint(), generate_feed() pelo código acima
2. Adicione o método add_query_vars(), handle_feed_request() e output_feed()
3. Desative e reative o plugin para atualizar as regras de rewrite
4. Teste o feed em: https://kinzancosmeticos.com/google-shopping-feed.xml
SOLUÇÃO ALTERNATIVA SE AINDA NÃO FUNCIONAR:
Acesse: WordPress Admin > Configurações > Links Permanentes > Salvar Alterações
Isso força a atualização das regras de rewrite.
*/
https://kinzancosmeticos.com/wp-sitemap-posts-page-1.xmlhttps://kinzancosmeticos.com/wp-sitemap-posts-product-1.xmlhttps://kinzancosmeticos.com/wp-sitemap-taxonomies-woodmart_slider-1.xmlhttps://kinzancosmeticos.com/wp-sitemap-taxonomies-product_brand-1.xmlhttps://kinzancosmeticos.com/wp-sitemap-taxonomies-product_cat-1.xmlhttps://kinzancosmeticos.com/wp-sitemap-taxonomies-product_tag-1.xmlhttps://kinzancosmeticos.com/wp-sitemap-users-1.xml