2016-05-27 5 views
1

Google Merchant Feedを設定していますが、その要件の1つは商品の出荷重量を含めることです。私はこのチュートリアルを使用しています:http://www.binaryforest.com/woocommerce-google-product-feed/WooCommerce:PHPを使用して製品の重量を返すことができますか?

どのように製品の重量は、PHPによってXMLに返すことができますか?

ご協力いただければ幸いです。

のfunctions.php:

//Define the product feed php page 
function products_feed_rss2() { 
$rss_template = get_template_directory() . '/product-feed.php'; 
load_template ($rss_template); 
} 

//Add the product feed RSS 
add_action('do_feed_products', 'products_feed_rss2', 10, 1); 

//Update the Rerewrite rules 
add_action('init', 'my_add_product_feed'); 

//function to add the rewrite rules 
function my_rewrite_product_rules($wp_rewrite) { 
$new_rules = array(
'feed/(.+)' => 'index.php?feed='.$wp_rewrite->preg_index(1) 
); 
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules; 
} 

//add the rewrite rule 
function my_add_product_feed() { 
global $wp_rewrite; 
add_action('generate_rewrite_rules', 'my_rewrite_product_rules'); 
$wp_rewrite->flush_rules(); 
} 

製品-feed.php

<?php 
/** 
* RSS2 Feed Template for displaying RSS2 Posts feed. 
* 
* @package WordPress 
*/ 

header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true); 
$more = 1; 

echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?> 

<rss version="2.0" 
    xmlns:content="http://purl.org/rss/1.0/modules/content/" 
    xmlns:wfw="http://wellformedweb.org/CommentAPI/" 
    xmlns:dc="http://purl.org/dc/elements/1.1/" 
    xmlns:atom="http://www.w3.org/2005/Atom" 
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/" 
    xmlns:g="http://base.google.com/ns/1.0" 
    <?php do_action('rss2_ns'); ?> 
> 

<channel> 
    <title><?php bloginfo_rss('name'); wp_title_rss(); ?></title> 
    <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" /> 
    <link><?php bloginfo_rss('url') ?></link> 
    <description>Skin care products for rosacea sufferers</description> 
    <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate> 
    <language><?php bloginfo_rss('language'); ?></language> 
    <sy:updatePeriod><?php echo apply_filters('rss_update_period', 'hourly'); ?></sy:updatePeriod> 
    <sy:updateFrequency><?php echo apply_filters('rss_update_frequency', '1'); ?></sy:updateFrequency> 
    <?php do_action('rss2_head'); ?> 
    <?php 
    $args = array('post_type' => 'product', 'posts_per_page' => 999); 
    $loop = new WP_Query($args); 
    while ($loop->have_posts()) : $loop->the_post(); global $product; 
    ?> 
    <item> 
     <title><?php the_title_rss() ?></title> 
     <link><?php the_permalink_rss() ?></link> 
     <g:image_link><?php echo wp_get_attachment_url(get_post_thumbnail_id()) ?></g:image_link> 
     <g:price><?php echo $product->price ?></g:price> 
     <g:condition>new</g:condition> 
     <g:id><?php echo $id; ?></g:id> 
     <g:availability>in stock</g:availability> 
     <g:google_product_category>Health &amp; Beauty &gt; Health Care &gt; Fitness &amp; Nutrition &gt; Vitamins &amp; Supplements </g:google_product_category> 
     <g:gtin><?php echo get_post_meta(get_the_ID(), '_cpf_upc', true); ?></g:gtin> 
     <g:brand><?php echo get_post_meta(get_the_ID(), '_cpf_brand', true); ?></g:brand> 
<?php if (get_option('rss_use_excerpt')) : ?> 
     <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> 
<?php else : ?> 
     <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> 
<?php endif; ?> 

<?php rss_enclosure(); ?> 
    <?php do_action('rss2_item'); ?> 
    </item> 
    <?php endwhile; ?> 
</channel> 
</rss> 

答えて

0

これは作業の答えです:

<g:shipping_weight><?php echo $product->weight ?></g:shipping_weight> 
関連する問題