Last active
April 27, 2017 05:10
-
-
Save kprajapatii/bf9f9568e6723cd3fb2a4dfa5a27cf00 to your computer and use it in GitHub Desktop.
Geodirectory: Display price packages as a select list. Put code in theme functions.php or via any snippet plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Display price packages as a select list | |
function gd_build_payment_select_list() { | |
global $post, $package_id; | |
$listing_type = !empty( $_REQUEST['listing_type'] ) ? sanitize_text_field( $_REQUEST['listing_type'] ) : ''; | |
$listing_type = empty( $listing_type ) && !empty( $post->post_type ) ? $post->post_type : $listing_type; | |
if ( isset( $_REQUEST['package_id'] ) ) { | |
$package_id = $_REQUEST['package_id']; | |
} else if ( !empty( $post->package_id ) ) { | |
$listing_type = $post->post_type; | |
$package_id = $post->package_id; | |
} else { | |
$default_package = geodir_get_default_package( $listing_type ); | |
$package_id = !empty( $default_package->pid ) ? $default_package->pid : ''; | |
} | |
$package_info = geodir_get_package_info( $package_id ); | |
$package_list_info = geodir_package_list_info( $listing_type ); | |
if ( is_page() && isset( $post->post_content ) && has_shortcode( $post->post_content, 'gd_add_listing' ) ) { | |
$page_id = $post->ID; | |
} else { | |
$page_id = geodir_add_listing_page_id(); | |
} | |
$postlink = geodir_getlink( get_permalink( $page_id ), array( 'listing_type' => $listing_type ), false ); | |
if ( !empty( $_REQUEST['pid'] ) ) { | |
$postlink = geodir_getlink( $postlink, array( 'pid' => $_REQUEST['pid'] ), false ); | |
} | |
if ( isset( $_REQUEST['package_id'] ) || ( !isset( $_REQUEST['pid'] ) || $_REQUEST['pid'] == '' ) ) { | |
$package_content = '<h5 id="geodir_fieldset_packages" class="geodir-fieldset-row" gd-fieldset="packages">' . SELECT_PACKAGE_TEXT . '</h5>'; | |
$package_content .= '<div class="geodir_price_package_row geodir_form_row geodir_custom_fields clearfix">'; | |
$package_content .= '<label>' . __( 'Package', 'geodir_payments' ) . '</label>'; | |
$package_content .= '<select name="package_id" id="package_id" class="geodir_textfield textfield_x chosen_select" data-placeholder="' . esc_attr__( 'Select Package', 'geodirectory' ) . '" option-ajaxchosen="false" onchange="window.location.href=\''. esc_url( $postlink ) . '&package_id=\' + this.value">'; | |
foreach ( $package_list_info as $pkg ) { | |
$alive_days = !empty( $pkg->days ) ? $pkg->days : 'unlimited'; | |
$pkg_desc = str_replace( 'number of publish days are', __( 'number of publish days are', 'geodir_payments' ), $pkg->title_desc ); | |
$package_content .= '<div id="geodir_price_package_' . $pkg->pid . '" class="geodir_package">'; | |
$package_content .= '<option value="' . $pkg->pid . '" ' . selected( (int)$package_id == (int)$pkg->pid, true, false ) . '>' . strip_tags( __( stripslashes_deep( $pkg_desc ), 'geodirectory') ) . '</option>'; | |
} | |
$package_content .= '</select></div>'; | |
echo $package_content; | |
} | |
} | |
function gd_plugins_loaded() { | |
remove_action( 'geodir_before_detail_fields' , 'geodir_build_payment_list', 1 ); | |
add_action( 'geodir_before_detail_fields' , 'gd_build_payment_select_list', 1 ); | |
} | |
add_action( 'plugins_loaded', 'gd_plugins_loaded' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment