קבלת שם המוצר לפי ה-ID בעזרת שורטקוד

PHOTO EMBED

Tue May 18 2021 13:13:32 GMT+0000 (UTC)

Saved by @Shesek

// 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' );
content_copyCOPY