For developers
Shortcode
Section titled “Shortcode”[wpify_woo_lowest_price]
Section titled “[wpify_woo_lowest_price]”Displays the lowest product price in the last 30 days.
Usage:
// In the product templateecho do_shortcode( '[wpify_woo_lowest_price]' );Output:
Formatted price using wc_price().
Programmatic retrieval of the lowest price
Section titled “Programmatic retrieval of the lowest price”// Get module instance$prices_log = wpify_woo_container()->get( \WpifyWoo\Modules\PricesLog\PricesLogModule::class);
// Get lowest price$lowest_price = $prices_log->get_lowest_price( $product_id );Data structure
Section titled “Data structure”Database table
Section titled “Database table”The module stores price history in its own table:
| Column | Type | Description |
|---|---|---|
id | INT | Primary key |
product_id | INT | Product ID |
regular_price | VARCHAR | Regular price (stored as text) |
sale_price | VARCHAR | Sale price (stored as text) |
created_at | VARCHAR | Entry date (format Y-m-d H:i:s) |
Repository
Section titled “Repository”// Get repository$repository = wpify_woo_container()->get( \WpifyWoo\Modules\PricesLog\PricesLogRepository::class);
// All product entries$logs = $repository->find_by_product_id( $product_id );
// Last entry$last = $repository->get_last_by_product_id( $product_id );
// Lowest price in 30 days$lowest = $repository->find_lowest_price( $product_id );Integration with the Prices module
Section titled “Integration with the Prices module”The Prices log module provides data for the Prices module (price type “Lowest price in 30 days”):
// In the Prices module:$module = wpify_woo_container()->get( \WpifyWoo\Modules\PricesLog\PricesLogModule::class);$price['value'] = $module->get_lowest_price( get_the_ID() );Example: Custom lowest price display
Section titled “Example: Custom lowest price display”add_action( 'woocommerce_single_product_summary', function() { global $product;
if ( ! $product->is_on_sale() ) { return; }
$prices_log = wpify_woo_container()->get( \WpifyWoo\Modules\PricesLog\PricesLogModule::class );
$lowest = $prices_log->get_lowest_price( $product->get_id() );
if ( $lowest && $lowest < $product->get_regular_price() ) { printf( '<div class="omnibus-price">%s: %s</div>', esc_html__( 'Lowest price in 30 days', 'my-theme' ), wc_price( $lowest ) ); }}, 15 );Example: Export price history
Section titled “Example: Export price history”function export_price_history( $product_id ) { $repository = wpify_woo_container()->get( \WpifyWoo\Modules\PricesLog\PricesLogRepository::class );
$logs = $repository->find_by_product_id( $product_id );
$data = []; foreach ( $logs as $log ) { $data[] = [ 'date' => $log->created_at, 'regular_price' => $log->regular_price, 'sale_price' => $log->sale_price, ]; }
return $data;}