0

In the file - wc-template-hooks.php (WC Version 2.1) , I see the action ~146

add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

The function lives in wc-template-functions.php

if ( ! function_exists( 'woocommerce_template_single_price' ) ) {

    /**
     * Output the product price.
     */
    function woocommerce_template_single_price() {
        wc_get_template( 'single-product/price.php' );
    }
}

The template file displays the price pulled product post type

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

global $product;

?>
<p class="price"><?php echo $product->get_price_html(); ?></p>

In file abstract-wc-product.php, the product base class is defined and get_price_html lives there. So how can I tie in a call to pull the price from an external database as we will not be storing any price in woocommerce products? I know about wp_remote_get() and will be using it to pull the price, but I'm not sure what to do next. Should I copy abstract-wc-product.php into my child theme and modify it? Or is there an easier way to override product price (which will be zero). Similarly, I want to do the same thing with stock on hand.

/**
 * Returns the price in html format.
 *
 * @param string $deprecated Deprecated param.
 *
 * @return string
 */
public function get_price_html( $deprecated = '' ) {
    if ( '' === $this->get_price() ) {
        $price = apply_filters( 'woocommerce_empty_price_html', '', $this );
    } elseif ( $this->is_on_sale() ) {
        $price = wc_format_sale_price( wc_get_price_to_display( $this, array( 'price' => $this->get_regular_price() ) ), wc_get_price_to_display( $this ) ) . $this->get_price_suffix();
    } else {
        $price = wc_price( wc_get_price_to_display( $this ) ) . $this->get_price_suffix();
    }

    return apply_filters( 'woocommerce_get_price_html', $price, $this );
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.