• 30-01-2025, 13:31:56
    #1
    Temanın function.php dosyasına alttaki kodu ekleyip kısa kod oluşturdum bu kod ürün açıklamasını çekiyor. Bu kodun sadece ilk cümleyi çekicek şekilde nasıl düzenliyebilirim

    add_shortcode( 'product_description', 'display_product_description' );
    function display_product_description( $atts ){    $atts = shortcode_atts( array(        'id' => get_the_id(),    ), $atts, 'product_description' );     global $product;     if ( ! is_a( $product, 'WC_Product') )        $product = wc_get_product($atts['id']);     return $product->get_description(); }
  • 30-01-2025, 13:34:45
    #2
    add_shortcode( 'product_description', 'display_product_description' );
    
    function display_product_description( $atts ) {
    $atts = shortcode_atts( array(
    'id' => get_the_id(),
    ), $atts, 'product_description' );
    
    global $product;
    
    if ( ! is_a( $product, 'WC_Product' ) )
    $product = wc_get_product( $atts['id'] );
    
    $description = $product->get_description();
    
    // İlk cümleyi almak için metni '.' karakterine göre ayır
    $first_sentence = strtok( $description, '.' );
    
    // İlk cümleyi döndür
    return $first_sentence . '.';
    }
  • 30-01-2025, 13:34:54
    #3
    Botcunuz
    $first_sentence = strtok($description, '.');  return $first_sentence . '.';
    en sona eklersek istediğimiz olur. yani:
    add_shortcode( 'product_description', 'display_product_description' );
    function display_product_description( $atts ){    
        $atts = shortcode_atts( array(
            'id' => get_the_id(),
        ), $atts, 'product_description' );
        
        global $product;
        
        if ( ! is_a( $product, 'WC_Product') )
            $product = wc_get_product($atts['id']);
        
        $description = $product->get_description();
        
        $first_sentence = strtok($description, '.');
        
        return $first_sentence . '.';
    }
  • 04-02-2025, 16:41:44
    #4
    Bu kodu eklediğimde rest-api sayfasında hata alıyordum. bende başka bi yerde bu kodu buldum. bu kodla açıklamayı nasıl tek cümleye düşürebilirm

    function custom_product_description($atts){    global $product;     try {        if( is_a($product, 'WC_Product') ) {            return wc_format_content( $product->get_description("shortcode") );        }         return "Product description shortcode run outside of product context";    } catch (Exception $e) {        return "Product description shortcode encountered an exception"; } }
    add_shortcode( 'custom_product_description', 'custom_product_description' );