fikrirasyid / woocommerce-newsletter-generator

Generate HTML email markup based on your WooCommerce products
8 stars 5 forks source link

show products in preview #1

Open gregoriopellegrino opened 9 years ago

gregoriopellegrino commented 9 years ago

Hi, I'm setting-up this plugin. I have some problems in showing the products in preview mode. I've created a function in my theme's functions.php file.

In preview mode wcng_get_value( $block_id, 'product', 'product_id', 0 ) returns always 0; instead if I publish the newsletter it returns the correct product_id.

fikrirasyid commented 9 years ago

Can you elaborate more about "in preview mode"? How can I replicate that issue?

gregoriopellegrino commented 9 years ago

I mean when the newsletter is editable in (the post is in draft state).

fikrirasyid commented 9 years ago

Can you share the screenshot? I seem not to have this kind of issue. Also, can you elaborate more on I've created a function in my theme's functions.php file.? A snippet of what you're doing will really help.

gregoriopellegrino commented 9 years ago

Sure. Here it is the screenshot. newsletter

Here the function of my snippet:

function effata_product_block( $block_id = '', $product_image_size = 'medium' ){

    // Get product data
    $product_id = wcng_get_value( $block_id, 'product', 'product_id', 0 );
    /*$permalink  = wcng_permalink( wcng_get_value( $block_id, 'product', 'permalink', '#' ) );
    $title      = wcng_get_value( $block_id, 'product', 'title', __( 'Product Name', 'woocommerce-newsletter-generator' ) );
    $price      = wcng_get_value( $block_id, 'product', 'price', '-' );
    $image      = wcng_get_value( $block_id, 'product', 'image', WC_NEWSLETTER_GENERATOR_URL . 'assets/default-product-image.png' );*/

    // Print wrapper for admin
    if( wcng_is_previewing() && wcng_current_user_can_edit_newsletter() ){
        echo "<div class='edit-content-block' data-type='product' data-id='$block_id' data-product-id='$product_id' data-product-image-size='$product_image_size'>";
        echo "<button class='toggle-edit-block'>". __( 'Edit', 'woocommerce-newsletter-generator' ) ."</button>";

        if($product_id == 0) {
    ?>
        <table>
            <tr>
                <td>
                    segnaposto per prodotto <?php echo $block_id; ?>
                </td>
            </tr>
        </table>
        <hr class="clear" />
    <?php
        }
    }

    if($product_id != 0) {
        $product = new WC_Product( $product_id );
    ?>
        <table id="libro01">
            <tr class="boxLibro" valign="top">
                <td class="boxLibroImg">
                    <a href="<?php echo $product->get_permalink(); ?>">
                        <?php
                            $image = $product->get_image('medium');
                            $image_metadata = wp_get_attachment_metadata( $product->get_image_id(), false);
                            $new_width = 180;
                            $new_height = (int) ($image_metadata["sizes"]["medium"]["height"] * $new_width / $image_metadata["sizes"]["medium"]["width"]);
                            $image = str_replace('width="'.$image_metadata["sizes"]["medium"]["width"].'"', 'width="'.$new_width.'"', $image);
                            $image = str_replace('height="'.$image_metadata["sizes"]["medium"]["height"].'"', 'height="'.$new_height.'"', $image);
                            echo $image;
                        ?>
                    </a>
                    <p class="prezzo"><?php echo "&euro; ".str_replace(".", ",", str_replace("€", "", $product->get_regular_price())); ?>&euro;</p>
                    <p class="informazioni"> <a href="<?php echo $product->get_permalink(); ?>">Scheda libro</a> </p>
                    <p class="informazioni"> <a href="http://www.effata.it/{{ anno }}/{{ mese }}/{{ libro.URLlibro|raw }}INT.pdf">Leggi le pagine introduttive</a> </p>
                    <p class="informazioni"> <a href="http://www.effata.it/{{ anno }}/{{ mese }}/{{ libro.URLlibro|raw }}INDICE.pdf">Leggi l'indice</a> </p>

                </td>

                <td>
                    <p class="autore">
                        <?php echo get_post_custom_values("authors", $product_id)[0]; ?>
                    </p>
                    <h2><a href="<?php echo $product->get_permalink(); ?>"><?php echo $product->get_title(); ?></a></h2>
                    <h5><?php echo get_post_custom_values("subtitle", $product_id)[0]; ?></h5>

                    <p class="anticipazione">
                        <?php echo my_excerpt($product->post->post_content, $product->post->post_excerpt); ?> <a href="<?php echo $product->get_permalink(); ?>">Leggi tutto...</a>
                    </p>
                    <p class="argomento"><?php echo $product->get_tags( ', ', '', ''); ?></p>
                </td>
            </tr>
        </table>
        <hr class="clear" />
    <?php
    }

    // Close wrapper for admin
    if( wcng_is_previewing() && wcng_current_user_can_edit_newsletter() ){
      echo "</div>";
    }
}