Created
November 29, 2018 18:35
-
-
Save tradesouthwest/7ae666396d5d5c0ba71c4445ea9f0e3b to your computer and use it in GitHub Desktop.
Memberpress gets all products to put in dropdown in admin settings page
This file contains hidden or 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
<?php | |
//gets all products to put in dropdown in admin settings page | |
function meprprorata_products_dropdown_cb($args, $access= array()) | |
{ | |
//$available = new MeprCouponsHelper::products_dropdown(); | |
$access = is_array($access) ? $access : array(); | |
$contents = array(); | |
$posts = MeprCptModel::all('MeprProduct'); | |
foreach($posts as $post) | |
$contents[$post->ID] = $post->post_title; | |
?> | |
<select name="<?php echo $args['name']; ?>" id="<?php echo $args['id']; ?>[]" | |
class="mepr-prorata-products-select" multiple="false"> | |
<option value="-1">Select Product to Associate Fee to</option> | |
<?php | |
foreach($contents as $curr_type => $curr_label) | |
{ | |
?> | |
<option value="<?php echo $curr_type; ?>" <?php echo (in_array($curr_type, $access))?'selected="selected"':''; ?>><?php echo $curr_label; ?> </option> | |
<?php | |
} | |
?> | |
</select> | |
Selected: <div id="MpprText"></div> | |
<p><?php print( $args['description'] ); ?></p> | |
<?php | |
} | |
/** | |
and in settings fields | |
*/ | |
add_settings_field( | |
'meprprorata_products_dropdown', | |
esc_attr__('Available Products', 'meprprorata'), | |
'meprprorata_products_dropdown_cb', | |
'meprprorata_options', | |
'meprprorata_options_section', | |
array( | |
'id' => 'MpprSelect', | |
'name' => 'meprprorata_products_dropdown', | |
'value' => empty( get_option( 'meprprorata_options' )['meprprorata_products_dropdown'] ) | |
? '2019-09-01' : get_option( 'meprprorata_options' )['meprprorata_products_dropdown'], | |
'description' => esc_html__( 'Select products that apply to', 'woocommerce' ) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment