Skip to content

Instantly share code, notes, and snippets.

@ditikos
Created December 30, 2016 14:35
Show Gist options
  • Save ditikos/c00c8bd96d3444871a300f07999bc471 to your computer and use it in GitHub Desktop.
Save ditikos/c00c8bd96d3444871a300f07999bc471 to your computer and use it in GitHub Desktop.
Compare a woocommerce product in En / Gr using WPML functions.
global $post;
define( 'WP_USE_THEMES', false );
/* Template Name: Price comparison */
/* Page needs to be in EN language */
get_header();
?>
<table>
<tr>
<th>Product Name</th>
<th>Original ID</th>
<th>Price In En</th>
<th>Price In Gr</th>
</tr>
<?php
$prefs = array(
post_type => "product",
post_status => "publish",
post_per_page => -1
);
$products = new WP_Query($prefs);
while ($products->have_posts()):
$products->the_post();
$en_product = get_the_ID();
$gr_product = apply_filters('wpml_object_id', $en_product, 'product', FALSE, 'el');
echo "<tr>\n";
echo "<td>".get_the_title()."</td>\n";
echo "<td>".$en_product."</td>\n";
echo "<td>".get_post_meta($en_product,'_price',true)."</td>\n";
echo "<td>".get_post_meta($gr_product,'_price',true)."</td>\n";
echo "</tr>";
endwhile;
wp_reset_postdata();
?>
</pre>
<?php
get_footer();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment