$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Php echo woocommerce price|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Php echo woocommerce price

matteradmin8PV0评论

Hi i am trying to echo with php the woocommerce product price in a specific area at my site. But it only works for single products. Not for variable products. What i must do?

Hi i am trying to echo with php the woocommerce product price in a specific area at my site. But it only works for single products. Not for variable products. What i must do?

Share Improve this question edited Oct 31, 2018 at 8:38 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Oct 30, 2018 at 21:24 Panagiotisou KoukouzelisPanagiotisou Koukouzelis 11 silver badge1 bronze badge 2
  • where do you want to display the price? on single product's page or another page? – Akshat Commented Oct 30, 2018 at 22:45
  • I want to display it on product page. But all my products are variable not single products – Panagiotisou Koukouzelis Commented Nov 1, 2018 at 6:37
Add a comment  | 

1 Answer 1

Reset to default 1

You can use either get_variation_prices( $for_display = false ) method or get_variation_regular_price( $min_or_max = 'min', $for_display = false )

Something like this:

global $product;
var_dump( $product->get_variation_prices() );

https://github/woocommerce/woocommerce/blob/master/includes/class-wc-product-variable.php#L97

/**
 * Get the min or max variation regular price.
 *
 * @param  string  $min_or_max Min or max price.
 * @param  boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
 * @return string
 */
public function get_variation_regular_price( $min_or_max = 'min', $for_display = false ) {
    $prices = $this->get_variation_prices( $for_display );
    $price  = 'min' === $min_or_max ? current( $prices['regular_price'] ) : end( $prices['regular_price'] );
    return apply_filters( 'woocommerce_get_variation_regular_price', $price, $this, $min_or_max, $for_display );
}

https://github/woocommerce/woocommerce/blob/master/includes/class-wc-product-variable.php#L80

/**
 * Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
 *
 * @param  bool $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
 * @return array Array of RAW prices, regular prices, and sale prices with keys set to variation ID.
 */
public function get_variation_prices( $for_display = false ) {
    $prices = $this->data_store->read_price_data( $this, $for_display );
    foreach ( $prices as $price_key => $variation_prices ) {
        $prices[ $price_key ] = $this->sort_variation_prices( $variation_prices );
    }
    return $prices;
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far