Support

Account

Home Forums General Issues Display custom fields in EDD widget

Helping

Display custom fields in EDD widget

  • HI ACF

    I started to use ACF about a week ago and I like the plugin.

    I’m selling music on my site using easydigitaldownloads plugin.
    easydigitaldownloads have a widget that display the download information on the sidebar. You can see the image.
    Using ACF I created 4 custom field which will give extra information about the file details, music details, track length and etc…

    I would like to display the custom fields below the download title and above the purchase button on that sidebar.

    Iv’e tried to paste the code <?php the_field($file_details); ?> in many different places on the php file but nothing displayed it. can you guys tell me why not or where to paste it?

    Here is the php file
    /**
    * Product Details Widget
    *
    * Displays a product’s details in a widget
    *
    * @since 1.9
    * @return void
    */
    class EDD_Product_Details_Widget extends WP_Widget {

    /** Constructor */
    public function __construct() {
    parent::__construct(
    ‘edd_product_details’,
    sprintf( __( ‘%s Details’, ‘edd’ ), edd_get_label_singular() ),
    array(
    ‘description’ => sprintf( __( ‘Display the details of a specific %s’, ‘edd’ ), edd_get_label_singular() ),
    )
    );
    }

    /** @see WP_Widget::widget */
    public function widget( $args, $instance ) {
    $args[‘id’] = ( isset( $args[‘id’] ) ) ? $args[‘id’] : ‘edd_download_details_widget’;

    if ( ! isset( $instance[‘download_id’] ) || ( ‘current’ == $instance[‘download_id’] && ! is_singular( ‘download’ ) ) ) {
    return;
    }

    // set correct download ID
    if ( ‘current’ == $instance[‘download_id’] && is_singular( ‘download’ ) ) {
    $download_id = get_the_ID();
    } else {
    $download_id = absint( $instance[‘download_id’] );
    }

    // Variables from widget settings
    $title = apply_filters( ‘widget_title’, $instance[‘title’], $instance, $args[‘id’] );
    $download_title = $instance[‘download_title’] ? apply_filters( ‘edd_product_details_widget_download_title’, ‘<h3>’ . get_the_title( $download_id ) . ‘</h3>’, $download_id ) : ”;
    $purchase_button = $instance[‘purchase_button’] ? apply_filters( ‘edd_product_details_widget_purchase_button’, edd_get_purchase_link( array( ‘download_id’ => $download_id ) ), $download_id ) : ”;
    $categories = $instance[‘categories’] ? $instance[‘categories’] : ”;
    $tags = $instance[‘tags’] ? $instance[‘tags’] : ”;

    // Used by themes. Opens the widget
    echo $args[‘before_widget’];

    // Display the widget title
    if( $title ) {
    echo $args[‘before_title’] . $title . $args[‘after_title’];
    }

    do_action( ‘edd_product_details_widget_before_title’ , $instance , $download_id );

    // download title
    echo $download_title;

    do_action( ‘edd_product_details_widget_before_purchase_button’ , $instance , $download_id );
    // purchase button
    echo $purchase_button;

    // categories and tags
    $category_list = $categories ? get_the_term_list( $download_id, ‘download_category’, ”, ‘, ‘ ) : ”;
    $category_count = count( get_the_terms( $download_id, ‘download_category’ ) );
    $category_labels = edd_get_taxonomy_labels( ‘download_category’ );
    $category_label = $category_count > 1 ? $category_labels[‘name’] : $category_labels[‘singular_name’];

    $tag_list = $tags ? get_the_term_list( $download_id, ‘download_tag’, ”, ‘, ‘ ) : ”;
    $tag_count = count( get_the_terms( $download_id, ‘download_tag’ ) );
    $tag_taxonomy = edd_get_taxonomy_labels( ‘download_tag’ );
    $tag_label = $tag_count > 1 ? $tag_taxonomy[‘name’] : $tag_taxonomy[‘singular_name’];

    $text = ”;

    if( $category_list || $tag_list ) {
    $text .= ‘<p class=”edd-meta”>’;

    if( $category_list ) {

    $text .= ‘<span class=”categories”>%1$s: %2$s</span><br/>’;
    }

    if ( $tag_list ) {
    $text .= ‘<span class=”tags”>%3$s: %4$s</span>’;
    }

    $text .= ‘
    ‘;
    }

    do_action( ‘edd_product_details_widget_before_categories_and_tags’, $instance, $download_id );

    printf( $text, $category_label, $category_list, $tag_label, $tag_list );

    do_action( ‘edd_product_details_widget_before_end’, $instance, $download_id );

    // Used by themes. Closes the widget
    echo $args[‘after_widget’];
    }

    /** @see WP_Widget::form */
    public function form( $instance ) {
    // Set up some default widget settings.
    $defaults = array(
    ‘title’ => sprintf( __( ‘%s Details’, ‘edd’ ), edd_get_label_singular() ),
    ‘download_id’ => ‘current’,
    ‘download_title’ => ‘on’,
    ‘purchase_button’ => ‘on’,
    ‘categories’ => ‘on’,
    ‘tags’ => ‘on’
    );

    $instance = wp_parse_args( (array) $instance, $defaults ); ?>

    <!– Title –>

    <label for=”<?php echo esc_attr( $this->get_field_id( ‘title’ ) ); ?>”><?php _e( ‘Title:’, ‘edd’ ) ?></label>
    <input class=”widefat” id=”<?php echo esc_attr( $this->get_field_id( ‘title’ ) ); ?>” name=”<?php echo esc_attr( $this->get_field_name( ‘title’ ) ); ?>” type=”text” value=”<?php echo $instance[‘title’]; ?>” />

    <!– Download –>
    <?php
    $args = array(
    ‘post_type’ => ‘download’,
    ‘posts_per_page’ => -1,
    ‘post_status’ => ‘publish’,
    );
    $downloads = get_posts( $args );
    ?>

    <label for=”<?php echo esc_attr( $this->get_field_id( ‘download_id’ ) ); ?>”><?php printf( __( ‘%s’, ‘edd’ ), edd_get_label_singular() ); ?></label>
    <select class=”widefat” name=”<?php echo esc_attr( $this->get_field_name( ‘download_id’ ) ); ?>” id=”<?php echo esc_attr( $this->get_field_id( ‘download_id’ ) ); ?>”>
    <option value=”current”><?php _e( ‘Use current’, ‘edd’ ); ?></option>
    <?php foreach ( $downloads as $download ) { ?>
    <option <?php selected( absint( $instance[‘download_id’] ), $download->ID ); ?> value=”<?php echo esc_attr( $download->ID ); ?>”><?php echo $download->post_title; ?></option>
    <?php } ?>
    </select>

    <!– Download title –>

    <input <?php checked( $instance[‘download_title’], ‘on’ ); ?> id=”<?php echo esc_attr( $this->get_field_id( ‘download_title’ ) ); ?>” name=”<?php echo esc_attr( $this->get_field_name( ‘download_title’ ) ); ?>” type=”checkbox” />
    <label for=”<?php echo esc_attr( $this->get_field_id( ‘download_title’ ) ); ?>”><?php _e( ‘Show Title’, ‘edd’ ); ?></label>

    <!– Show purchase button –>

    <input <?php checked( $instance[‘purchase_button’], ‘on’ ); ?> id=”<?php echo esc_attr( $this->get_field_id( ‘purchase_button’ ) ); ?>” name=”<?php echo esc_attr( $this->get_field_name( ‘purchase_button’ ) ); ?>” type=”checkbox” />
    <label for=”<?php echo esc_attr( $this->get_field_id( ‘purchase_button’ ) ); ?>”><?php _e( ‘Show Purchase Button’, ‘edd’ ); ?></label>

    <!– Show download categories –>

    <?php $category_labels = edd_get_taxonomy_labels( ‘download_category’ ); ?>
    <input <?php checked( $instance[‘categories’], ‘on’ ); ?> id=”<?php echo esc_attr( $this->get_field_id( ‘categories’ ) ); ?>” name=”<?php echo esc_attr( $this->get_field_name( ‘categories’ ) ); ?>” type=”checkbox” />
    <label for=”<?php echo esc_attr( $this->get_field_id( ‘categories’ ) ); ?>”><?php printf( __( ‘Show %s’, ‘edd’ ), $category_labels[‘name’] ); ?></label>

    <!– Show download tags –>

    <?php $tag_labels = edd_get_taxonomy_labels( ‘download_tag’ ); ?>
    <input <?php checked( $instance[‘tags’], ‘on’ ); ?> id=”<?php echo esc_attr( $this->get_field_id( ‘tags’ ) ); ?>” name=”<?php echo esc_attr( $this->get_field_name( ‘tags’ ) ); ?>” type=”checkbox” />
    <label for=”<?php echo esc_attr( $this->get_field_id( ‘tags’ ) ); ?>”><?php printf( __( ‘Show %s’, ‘edd’ ), $tag_labels[‘name’] ); ?></label>

    <?php do_action( ‘edd_product_details_widget_form’ , $instance ); ?>
    <?php }

    /** @see WP_Widget::update */
    public function update( $new_instance, $old_instance ) {
    $instance = $old_instance;

    $instance[‘title’] = strip_tags( $new_instance[‘title’] );
    $instance[‘download_id’] = strip_tags( $new_instance[‘download_id’] );
    $instance[‘download_title’] = isset( $new_instance[‘download_title’] ) ? $new_instance[‘download_title’] : ”;
    $instance[‘purchase_button’] = isset( $new_instance[‘purchase_button’] ) ? $new_instance[‘purchase_button’] : ”;
    $instance[‘categories’] = isset( $new_instance[‘categories’] ) ? $new_instance[‘categories’] : ”;
    $instance[‘tags’] = isset( $new_instance[‘tags’] ) ? $new_instance[‘tags’] : ”;

    do_action( ‘edd_product_details_widget_update’, $instance );

    return $instance;
    }

    }

    Any help will be much appreciated.

    Thank you!

  • Your first step should be to contact the developer of EDD and ask them if it is possible to display custom field content in the sidebar widget and how that can be done.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.