woocommerce product price database code example

Example 1: how to get woocommerce product price

$_product->get_regular_price();
$_product->get_sale_price();
$_product->get_price();

Example 2: woocommerce mysql price table

//for Regular Price
UPDATE wp_postmeta 
SET meta_value = diff_price_value 
WHERE post_id = variation_id AND meta_key = '_regular_price';

//for Price
UPDATE wp_postmeta 
SET meta_value = price_value 
WHERE post_id = variation_id AND meta_key = '_price';

//for Sale Price
UPDATE wp_postmeta 
SET meta_value = price_value 
WHERE post_id = variation_id AND meta_key = '_sale_price';

Example 3: how to get woocommerce product price

function so_30165014_price_shortcode_callback( $atts ) {
    $atts = shortcode_atts( array(
        'id' => null,
    ), $atts, 'bartag' );

    $html = '';

    if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){
         $_product = wc_get_product( $atts['id'] );
         $html = "price = " . $_product->get_price();
    }
    return $html;
}
add_shortcode( 'woocommerce_price', 'so_30165014_price_shortcode_callback' );

Tags:

Sql Example