Hi, is possible add single product variation near sku into product template?
See private content for details..
Thanks
This topic has 10 replies, 2 voices, and was last updated 5 months ago ago by Luca Rossi
Hi, is possible add single product variation near sku into product template?
See private content for details..
Thanks
Dear @M.,
We hope this message finds you well.
We are still unclear about certain aspects of your website. Could you kindly provide more detailed information or share any relevant images or videos that might help us better understand the issue?
Thank you in advance for your cooperation.
Best regards,
The 8Theme Team
I want add specific product attribute near SKU
Dear @M.,
We hope this message finds you well.
To display the manufacturer code below the SKU element, you can create a custom shortcode as follows:
add_shortcode( 'codice_produttore', 'shortcode_codice_produttore' );
function shortcode_codice_produttore() {
$attribute_value = wc_get_product()->get_attribute('pa_codice_produttore');
if ( $attribute_value ) {
echo 'Attribute: ' . esc_html( $attribute_value );
}
}
Once the shortcode [codice_produttore] is created, you may insert it directly below the SKU element in your template.
Should you need any further assistance, please do not hesitate to contact us.
Best regards,
The 8Theme Team
I’ve added this code:
add_shortcode( ‘codice_produttore’, ‘shortcode_codice_produttore’ );
function shortcode_codice_produttore() {
$attribute_value = wc_get_product()->get_attribute(‘codice-produttore’);
if ( $attribute_value ) {
echo ‘Code: ‘ . esc_html( $attribute_value );
}
}
But this print all products attributes, il possible display only the attribute of selected variation?
Thanks
Hi @M.
Can you please try with this code instead?
add_shortcode( 'codice_produttore', 'shortcode_codice_produttore' );
function shortcode_codice_produttore() {
global $product;
// If no global product, try to get current product
if ( ! $product ) {
global $post;
if ( $post && $post->post_type === 'product' ) {
$product = wc_get_product( $post->ID );
}
}
// Return empty if no product found
if ( ! $product ) {
return '';
}
// Get attribute value for both simple and variation products
$attribute_value = $product->get_attribute( 'codice-produttore' );
// If it's a variation and no attribute found, try parent product
if ( ! $attribute_value && $product->is_type( 'variation' ) ) {
$parent_product = wc_get_product( $product->get_parent_id() );
if ( $parent_product ) {
$attribute_value = $parent_product->get_attribute( 'codice-produttore' );
}
}
// Return the attribute value if found
if ( $attribute_value ) {
return 'Code: ' . esc_html( $attribute_value );
}
return '';
}
Let us know how it goes!
Same result… I see all variations code.
I think i’ve to add javascript code in order to update value if click on variations (like SKU), right?
Dear @M.,
We hope this message finds you well.
Regarding your request related to JavaScript, you may consider using the following custom script:
jQuery(function($){
$('form.cart').on('show_variation', function(event, data) {
console.log(data);
});
});
We hope this proves helpful. Should you have any further questions or require additional assistance, please do not hesitate to reach out.
Best regards,
The 8Theme Team
I can’t obtain right code, if I send FTP credential and WP admin access can you help me?
My goal il put ‘codice-produttore’ near SKU and update when update variations like SKU value
Thanks
Hi @M.,
Could you please provide the FTP account details and WordPress admin access so that we can review the issue and determine what assistance we can offer?
Please note that, as this request falls outside the scope of our standard support policy, we cannot guarantee a 100% resolution. However, we will do our best to help.
Best regards,
The 8Theme Team
You must be logged in to reply to this topic.Log in/Sign up