Adding & ordering Hooks to Single Product Page
-
I have added two hooks on my child theme function.php. The hooks to add Number of Products available and products sold.
The hooks are working well. My only problem is that I would like to change the position of Product sold from below the title to below the price. See screenshot link.
Screenshot link: https://egacoupons.com/wp-content/uploads/2017/07/Picture10.png
Product single page link: https://egacoupons.com/producto/clases-de-ingles-one-to-one/
// usage example: Only [product_stock id=”1592″] available!
add_shortcode(‘product_stock’, ‘product_stock’);
function product_stock( $atts ) {
if ( ! $atts[‘id’] ) {
return ”;
}
$product = get_product($atts[‘id’]);
return $product->stock; // prints 22, ie the qty of product 1592
}// Add unit sold below product title.
add_action( ‘woocommerce_single_product_summary’, ‘wc_product_sold_count’, 11 );
function wc_product_sold_count() {
global $product;
$units_sold = get_post_meta( $product->id, ‘total_sales’, true );
echo ‘<p>’ . sprintf( __( ‘Unidades Vendidas: %s’, ‘woocommerce’ ), $units_sold ) . ‘</p>’;
}
- The topic ‘Adding & ordering Hooks to Single Product Page’ is closed to new replies.