• Resolved eganet

    (@eganet)


    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>’;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The third parameter of the add_action() “11” is the priority. Higher numbers will come lower in the sequence of elements. “11” should be after the price in a WooCommerce template so maybe you have a theme template for that page. You might be able to see the numbering system at:
    wp-content/themes/icommerce/woocommerce/content-single-product.php
    If not, increase the value, say by 5 or 10 at a time and test.

    Thread Starter eganet

    (@eganet)

    lorro thanks a million. It worked!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding & ordering Hooks to Single Product Page’ is closed to new replies.