The snippet below allows selecting restricted listing attributes per package (by selecting them in the package settings). These attribute fields are then not available for editing unless the corresponding listing package is selected/purchased. This is a temporary solution until we add this functionality to the next major Memberships update.
add_filter( 'hivepress/v1/meta_boxes/listing_package_settings', 'hp_add_package_fields', 1000 );
add_filter( 'hivepress/v1/models/listing_package', 'hp_add_package_fields', 1000 );
add_filter( 'hivepress/v1/models/user_listing_package', 'hp_add_package_fields', 1000 );
function hp_add_package_fields( $form ) {
$attributes = array_filter( wp_list_pluck( hivepress()->attribute->get_attributes( 'listing' ), 'label' ) );
$form['fields']['attributes'] = [
'label' => 'Attributes',
'type' => 'select',
'options' => $attributes,
'multiple' => true,
'_external' => true,
'_order' => 100,
];
return $form;
}
add_filter(
'hivepress/v1/forms/listing_update',
function( $form ) {
if ( current_user_can( 'edit_others_posts' ) ) {
return $form;
}
$packages = \HivePress\Models\Listing_Package::query()->filter(
[
'status' => 'publish',
]
)->get();
$package_attributes = [];
foreach ( $packages as $package ) {
$package_attributes = array_merge( $package_attributes, (array) $package->get_attributes() );
}
$package_attributes = array_unique( $package_attributes );
$user_packages = \HivePress\Models\User_Listing_Package::query()->filter(
[
'user' => get_current_user_id(),
]
)->get();
$user_attributes = [];
foreach ( $user_packages as $package ) {
$user_attributes = array_merge( $user_attributes, (array) $package->get_attributes() );
}
$user_attributes = array_unique( $user_attributes );
foreach ( $package_attributes as $attribute ) {
if ( ! in_array( $attribute, $user_attributes ) ) {
unset( $form['fields'][ $attribute ] );
}
}
return $form;
},
1000
);
add_filter(
'hivepress/v1/menus/listing_submit',
function( $menu ) {
if ( isset( $menu['items']['listing_submit_package'] ) ) {
$menu['items']['listing_submit_package']['_order'] = 15;
}
return $menu;
},
1000
);
add_filter(
'hivepress/v1/templates/listing_submit_package_page',
function( $template ) {
hivepress()->template->fetch_block( $template, 'listing_details_change_link' );
return $template;
},
1000
);
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.