Шорткод, отображающий название продукта и цену на странице продукта WooCommerce ⇐ Php

Кемеровские программисты php общаются здесь
Anonymous
Шорткод, отображающий название продукта и цену на странице продукта WooCommerce

Сообщение Anonymous »

Мне нужно показать заголовок продукта и текущую цену с помощью короткометражного кода на странице продукта без использования идентификатора продукта. цена. < /p>
// Get WooCommerce product price by ID via shortcode: [iw_product_price id='']
function iw_product_price_shortcode( $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 = $_product->get_price_html();
}
return $html;
}
add_shortcode( 'iw_product_price', 'iw_product_price_shortcode' );

// Get WooCommerce product name by ID via shortcode: [iw_product_name id='']
function iw_product_name_shortcode( $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 = $_product->get_title();
}
return $html;
}
add_shortcode( 'iw_product_name', 'iw_product_name_shortcode' );


Подробнее здесь: https://stackoverflow.com/questions/765 ... oduct-page

Вернуться в «Php»