Home › Forums › WoodMart support forum › Showing other product data in simple product page
Showing other product data in simple product page
- This topic has 8 replies, 3 voices, and was last updated 3 years, 8 months ago by dido76bg.
-
AuthorPosts
-
March 12, 2021 at 10:06 am #272979
yosnapParticipantHello,
How can I join the Extra product info in the Product info, as showed in the ss. I would like to keep the Product info format and just merge with the other product data. Can you help me?Thank you
Attachments:
You must be logged in to view attached files.March 12, 2021 at 10:55 am #273014
dido76bgParticipantHi!
You should create them as attributes and check them not to show on product page (or if you want you can leave them). Then you shoul create e custom function in your child theme functions.php file.
March 12, 2021 at 11:40 am #273040
Aizaz Imtiaz AwanKeymasterHello,
@yosnap First of all thanks for choosing our Theme, we are glad to be you in the WoodMart WordPress family :).I saw the screenshot you attached.
You need to create them as attributes as well then they will be displayed in the table as you added above.
@dido76bg Thanks for your involvement.Best Regards
March 12, 2021 at 12:47 pm #273077
yosnapParticipantThank you for answering,
I’ve already edited the functions file and created a custom function, but I don’t know how to show that data in the table. I create a PHP code to show that as block bellow the product info
March 12, 2021 at 1:06 pm #273090
Aizaz Imtiaz AwanKeymasterMarch 12, 2021 at 2:20 pm #273109
dido76bgParticipantHi!
If you want it to be easier you can name your attribures to start with pinfo_ – for product info section and einfo_ – for extra info sections so you can call the with foreach.
It is a more complex solution than adding attributes to an array but it is all up to you.
For example:
function mycustom_productpage_attributesinfo(){
global $product;
$attributes = $product->get_attributes();
if ( ! $attributes ) {
return;
}
$outputpi = ‘<div class=”custom-product-attributes-show”>’;
/*product info*/
$outputpi .= ‘<div class=”label”>Product Info</div>’;
foreach ( $attributes as $attribute ) {
$attribute_slug = str_replace( ‘pa_’, ”, $attribute->get_name() );
if ( $attribute->get_variation() ) { //skip variations
continue;
}
$name = $attribute->get_name();
if ( $attribute->is_taxonomy() && strstr($attribute_slug, ‘pinfo_’) ) {
$terms = wp_get_post_terms( $product->get_id(), $name, ‘all’ );
$tax = $terms[0]->taxonomy;
$tax_object = get_taxonomy($tax);
if ( isset ( $tax_object->labels->singular_name ) ) {
$tax_label = $tax_object->labels->singular_name;
} elseif ( isset( $tax_object->label ) ) {
$tax_label = $tax_object->label;
if ( 0 === strpos( $tax_label, ‘Product ‘ ) ) {
$tax_label = substr( $tax_label, 8 );
}
}
$outputpi .= ‘<div class=”‘ . esc_attr( $name ) . ‘”>’;
$outputpi .= ‘<span class=”attribute-label”>’ . esc_html( $tax_label ) . ‘: </span> ‘;
$tax_terms = array();
foreach ( $terms as $term ) {
$single_term = esc_html( $term->name );
array_push( $tax_terms, $single_term );
}
$outputpi .= ‘<span class=”attribute-value”>’ . implode(‘, ‘, $tax_terms) . ‘</span></div>’;
}
}
/*end product info*/
/*extra info*/
$outputpi .= ‘<div class=”label”>Extra Info</div>’;
foreach ( $attributes as $attribute ) {
$attribute_slug = str_replace( ‘pa_’, ”, $attribute->get_name() );
if ( $attribute->get_variation() ) { //skip variations
continue;
}
$name = $attribute->get_name();
if ( $attribute->is_taxonomy() && strstr($attribute_slug, ‘einfo_’) ) {
$terms = wp_get_post_terms( $product->get_id(), $name, ‘all’ );
$tax = $terms[0]->taxonomy;
$tax_object = get_taxonomy($tax);
if ( isset ( $tax_object->labels->singular_name ) ) {
$tax_label = $tax_object->labels->singular_name;
} elseif ( isset( $tax_object->label ) ) {
$tax_label = $tax_object->label;
if ( 0 === strpos( $tax_label, ‘Product ‘ ) ) {
$tax_label = substr( $tax_label, 8 );
}
}
$outputpi .= ‘<div class=”‘ . esc_attr( $name ) . ‘”>’;
$outputpi .= ‘<span class=”attribute-label”>’ . esc_html( $tax_label ) . ‘: </span> ‘;
$tax_terms = array();
foreach ( $terms as $term ) {
$single_term = esc_html( $term->name );
array_push( $tax_terms, $single_term );
}
$outputpi .= ‘<span class=”attribute-value”>’ . implode(‘, ‘, $tax_terms) . ‘</span></div>’;
}
}
/*end extra info*/$outputpi .= ‘</div>’;
echo $outputpi;
}
add_action( ‘woocommerce_single_product_summary’, ‘mycustom_productpage_attributesinfo’, 25 ); /*you ca add your own hook*/March 12, 2021 at 5:46 pm #273150
yosnapParticipantSorry but I’ve got confused because I’m not familiar with code. I would like to use it with Elementor
Is there anyway to remove the Product info section?
Thank you
March 13, 2021 at 6:33 am #273209
Aizaz Imtiaz AwanKeymasterMarch 13, 2021 at 7:19 am #273215
dido76bgParticipantHi!
Elementor has nothing to do with the code.
I am a little bit confused because the code that I have shared is as you asked in your picture.
Now you don’t want the product info.
Please be more specific.
Do you want to remove the product info tab, or you want to remove Product info from my code? -
AuthorPosts
Tagged: custom fields, extra fields
- You must be logged in to create new topics. Login / Register