Reputation: 157
I'm editing a WordPress eCommerce site and I need help adding something to a PHP file. I want to move the code that generates the tags to a different PHP file but I have not been able to do it successfully yet. I figured out that the line of code I need to move is this:
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Model:', 'Models:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?>
And this is the file I want to move it to:
<?php
/**
* Description tab
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $post;
$heading = esc_html( apply_filters( 'woocommerce_product_description_heading', __( 'Product Description', 'woocommerce' ) ) );
?>
<?php if ( $heading ): ?>
<h2><?php echo $heading; ?></h2>
<?php endif; ?>
<?php the_content(); ?>
Just in case this matters, the page the line of code comes from is this:
<?php
/**
* Single Product Meta
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $post, $product;
$cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
$tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
?>
<div class="product_meta">
<?php do_action( 'woocommerce_product_meta_start' ); ?>
<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
<span class="sku_wrapper"><?php _e( 'PR PN:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span></span><br>
<?php endif; ?>
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Model:', 'Models:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?>
<?php echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'OEM PN:', 'OEM PN:', $tag_count, 'woocommerce' ) . ' ', '</span>' ); ?>
<?php do_action( 'woocommerce_product_meta_end' ); ?>
</div>
Upvotes: 0
Views: 577
Reputation: 65254
I believe those are template files.. Just edit those files...
Steps:
create a folder in your theme named woocommerce.
copy those templates files in in your theme woocommerce folder. Same hierarchy as if templates folder is your woocommerce folder. So your plugins\woocommerce\templates\single-product\tabs\description.php
should be copied to your-theme\woocommerce\single-product\tabs\description.php
Do your edits on those files. and you're safe.
Source: Template Structure + Overriding Templates via a Theme
Upvotes: 2