Answers for "woocommerce update product price programmatically"

3

how to get woocommerce product price

$_product->get_regular_price();
$_product->get_sale_price();
$_product->get_price();
Posted by: Guest on May-21-2020
1

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' );
Posted by: Guest on May-21-2020
0

WooCommerce Add Text after Price to Specific Product or Products

add_filter( 'woocommerce_get_price_html', 'njengah_text_after_price' );

function njengah_text_after_price($price){
	
	global $post;
		
	$product_id = $post->ID;
	
	$product_array = array( 1,2,3 );//add in the product IDs to add text after price
	
	if ( in_array( $product_id, $product_array )) {
		
		$text_to_add_after_price  = ' text to add after price for the specific products '; //change text in bracket to your preferred text 
		  
		  return $price .   $text_to_add_after_price;
		  
	}else{
		
		return $price; 
	}
		  
}
Posted by: Guest on June-21-2021

Code answers related to "woocommerce update product price programmatically"

Browse Popular Code Answers by Language