Reputation: 9
For example, my SKU number is "ZKY-KDN-KTP-167754" I want to show only number "167754" and hide the letters. Without deleting.
Is it possible?
Upvotes: 0
Views: 579
Reputation: 855
You have 2 options here:
Replace the single product template (woocommerce/templates/single-product/meta.php) from your theme, and where is the sku you can use a REGEX to keep only numbers like this:
<?php do_action( 'woocommerce_product_meta_start' ); ?>
<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
$sku = $product->get_sku() ? $sku : esc_html__( 'N/A', 'woocommerce' );
$sku = preg_replace('/\D/', '', $sku);
<span class="sku_wrapper"><?php esc_html_e( 'SKU:', 'woocommerce' ); ?> <span class="sku"><?php echo $sku; ?></span></span>
<?php endif; ?>
<?php echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</span>' ); ?>
<?php echo wc_get_product_tag_list( $product->get_id(), ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', count( $product->get_tag_ids() ), 'woocommerce' ) . ' ', '</span>' ); ?>
<?php do_action( 'woocommerce_product_meta_end' ); ?>
Use Javascript (non-recommended)
Upvotes: 1
Reputation: 1037
What you could do is to give the class="sku_wrapper"
an visibility: hidden;
.
And give the class="sku"
wich is inside the sku_wrapper an visibility: initial;
Tested and works
Upvotes: 1