xxxxxxxxxx
$_product->get_regular_price();
$_product->get_sale_price();
$_product->get_price();
xxxxxxxxxx
$product_id = 1100;
$product = wc_get_product($product_id);
echo $product->get_stock_quantity();
xxxxxxxxxx
$product = wc_get_product( $post_id );
$product->get_regular_price();
$product->get_sale_price();
$product->get_price();
xxxxxxxxxx
if ($product->is_type( 'simple' )) {
$sale_price = $product->get_sale_price();
$regular_price = $product->get_regular_price();
}
elseif($product->is_type('variable')){
$sale_price = $product->get_variation_sale_price( 'min', true );
$regular_price = $product->get_variation_regular_price( 'max', true );
}
$discount = round (($sale_price / $regular_price -1 ) * 100);
}
xxxxxxxxxx
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' );
xxxxxxxxxx
/**
*
* Add Product Tags Above The Add To Cart Form
*
*/
add_action( 'woocommerce_before_add_to_cart_form', 'dwc_print_tags_under_description' );
function dwc_print_tags_under_description() {
// This will hold all of our product tags
$tags = array();
// get an array of the WP_Term objects for a defined product ID (get_the_id() will return the product id of the current object)
$terms = wp_get_post_terms( get_the_id(), 'product_tag' );
// Loop through each product tag for the current product
if ( count( $terms ) > 0 ) {
foreach( $terms as $term ) {
// Product Tag Name
$term_name = $term->name;
// Product Tag Link
$term_link = get_term_link( $term, 'product_tag' );
// Set the product tag names in an array
$tags[] = '<a class="product-tag-badge" href="'.$term_link.'">' . $term_name . '</a>';
}
// Combine all of the product tags into one string for output
$tags = implode( '', $tags );
// Output
echo $tags;
}
}