Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 14:00 9:00 – 14:00 9:00 – 14:00 9:00 – 14:00 9:00 – 14:00 -
- 15:00 – 18:00 15:00 – 18:00 15:00 – 18:00 15:00 – 18:00 15:00 – 18:00 -

Supporter timezone: Europe/Athens (GMT+03:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Andreas 1 year, 10 months ago.

Assisted by: Andreas.

Author Posts
March 6, 2023 at 8:51 am #13176115

innovexA

Tell us what you are trying to do?
I create a custom function, in my function I create a card in which product details is showing but when translate website card is not showing.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

gSTiNH.png
gkmOmi.png
March 6, 2023 at 12:47 pm #13178835

Andreas

Hello there

Thank you for contacting us. I am happy to help you.

May I ask you to share exactly what you did in order to understand your implementation and see how we can help you?

Also from your images is not clear what is your problem. Also, may I ask you to share with me what you are expecting to see with your implementation?

Regards,
Andreas

March 7, 2023 at 10:05 am #13187745

innovexA

Here is my code
add_shortcode('sold', 'wp_product_solda_count');
function wp_product_solda_count($atts) {
global $product;
extract( shortcode_atts( array(
'category' => ''
), $atts ) );
$args = array(
'post_type' => 'product',
'product_cat' => $category,

'posts_per_page' => 3
);

$loop = new WP_Query( $args );
echo '<wpml-config><div class="cont">';
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$sale= get_post_meta( $product->get_id(), '_' . 'prowc_product_countdown_date', true );
$date_now = date("Y-m-d");
if($date_now < $sale){
echo '<div class="card">';
echo '<div class="conc"><br />' . woocommerce_get_product_thumbnail('thumbnail_image_width').' </div>

<div class="container cr">

<p class="ida">
</p>

';
// echo' <b class="my-font sta" style="color:black;"> '. $product->get_id().'</b><br>';
//echo $product;
echo '<div class="conf"><b class="my-font st"> '.get_the_title().'</b>'; echo "<br>";
echo '<div class="con">';
if(!empty($product->get_sale_price())){
echo'<del class="my-font sta"> $'.$product->get_regular_price().'</del>
<b class="my-font sta"> $'. $product->get_sale_price().'</b>
';
}else{
echo'
<b class="my-font sta"> $'. $product->get_regular_price().'</b>
';
}
echo'</div>';
if(!empty(get_post_meta( $product->get_id(), '_' . 'prowc_product_countdown_date', true ))){
echo'<div class="cona">
<span class="prowc_product_countdown" product_id="'.$product->get_id().'" style="font-size: 14px;"></span>
</div> ';
}
$total_sold = get_post_meta( $product->get_id(), 'total_sales', true );
if ( $total_sold ) echo '<b class="my-font stb">
' . sprintf( __( 'Sold: %s', 'woocommerce' ), $total_sold ) . '

</b> |';
if ( !empty($product->get_stock_quantity() )){
echo'<b class="my-font stb"> Total Stock '. $product->get_stock_quantity().'</b><br>';
}
echo'<br>';
echo "<div class='cond'>";
echo "
<span class='xt_wooqv-show-on-all'>Details</span>
";
echo "Buy Now";
echo ' </div></div></div> <div class="cra"> <p class="num"> ID <br> 00000 </p>
</div></div>';
}
endwhile;
echo '</div></wpml-config>';
wp_reset_query();

}

I attach images so you can understand what I want. In this function I'm showing woocommerce products details in cards but when translate web cards is not showing can you please help me in this matter?

TEMPLATE2.jpg
TEMPLATE2.jpg
TEMPLATE.jpg
March 7, 2023 at 2:25 pm #13190303

Andreas

Thank you very much for the code.

First of all I would like to inform you that giving support to custom code is out of the scope of this forum.

I can give you some hints though.

1) It is good to use WooCommerce and WPML hooks

https://woocommerce.com/document/introduction-to-hooks-actions-and-filters/

https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

2) In general if you add this in the footer and you are in the product details page it will return the product id based on the language you are. :

global $product;

var_dump( $product->get_id() );

But it will not work if you are on an archive page. You need there to take the id of the product in the original language, find the id of the translated one with WPML Hooks and then retrieve the rest of the details.

3) Please avoid using <wpml-config> . We are using this in our language configuration files. It s not the same( HTML vs XML ) but I am pretty sure that we didn't test such kinds of scenarios in order to find conflicts.

https://wpml.org/documentation/support/language-configuration-files/

I hope this helps. Please let us know how it goes or if you need any further assistance. I'll gladly help you. 🙂

Regards,
Andreas

The topic ‘[Closed] custom function translate’ is closed to new replies.