Exposing All Loop variables for custom plugin

I’m writing our own plugin and theme for use with Marketpress. I’ve been unable to find a support page that documents how to best expose all meta data variables as pulled from a single product in this case.

Specifically, in this case I am wishing to get the value of the Sale Price: Price, Start Date, End Date

Thanks in advance.

  • Milan
    • WordPress Wizard

    Hello @amazon,

    I hope you are having a good day and thanks for asking us. :slight_smile:

    There are two meta stored for each product about sales price start date and end date which are,

    #1) sale_price_start_date

    #2) sale_price_end_date

    You can fetch those data for each product with the help of get_meta function of MP_Product class. For more information on MP_Product class, please refer /wp-content/plugins/marketpress/includes/common/class-mp-product.php file.

    Now you can use something like this in your custom loop to get those data. :slight_smile:

    <?php

    if ( have_posts() ) {
    while ( have_posts() ) {
    the_post();
    $product_id = get_the_ID();
    $product = new MP_Product( $product_id );

    $has_sale = $product->get_meta( 'has_sale' );
    $sale_price = $product->get_meta( 'sale_price_amount' );
    $on_sale = false;

    if ( $has_sale && $sale_price ) {
    $start_date = $product->get_meta( 'sale_price_start_date', false, true );
    $end_date = $product->get_meta( 'sale_price_end_date', false, true );
    $time = current_time( 'Y-m-d' );
    $on_sale = true;

    if ( $start_date && $time < $start_date ) {
    $on_sale = false;
    } elseif ( $end_date && $time > $end_date ) {
    $on_sale = false;
    }
    }

    //
    // Post Content here
    //
    } // end while
    } // end if

    I hope this helps you. :slight_smile:

    Please let us know if you need further assistance. :slight_smile: We are happy to help you.

    Cheers,

    Milan