Skip to content

Instantly share code, notes, and snippets.

View MjHead's full-sized avatar

Andrew Shevchenko MjHead

  • Crocoblock
  • Ukraine
View GitHub Profile
@MjHead
MjHead / jet-angine-appointments-query.sql
Created January 27, 2024 15:55
JetEngine. SQL query to get appointments with service name and service category name. Replace product_cat with your actual taxonomy slug
SELECT app.*, posts.post_title AS service_name, terms.name AS service_category
FROM {prefix}jet_appointments AS app
INNER JOIN {prefix}posts AS posts ON posts.ID = app.service
INNER JOIN {prefix}term_relationships AS terms_rel ON posts.ID = terms_rel.object_id
INNER JOIN {prefix}term_taxonomy AS term_tax ON terms_rel.term_taxonomy_id = term_tax.term_taxonomy_id
INNER JOIN {prefix}terms AS terms ON term_tax.term_id = terms.term_id
WHERE term_tax.taxonomy = 'product_cat'
@MjHead
MjHead / form-custom-hook.php
Created September 19, 2021 08:07
JetFormBuilder. Example of custom hook with API request and redirect.
<?php
/**
* 'api-request' - is a customm hook name
*/
add_action( 'jet-form-builder/custom-action/api-request', function( $request, $action_handler ) {
$post_id = ! empty( $request['inserted_post_id'] ) ? $request['inserted_post_id'] : false;
if ( ! $post_id ) {
return;
@MjHead
MjHead / jet-booking-add-cpt.php
Created January 17, 2024 16:11
JetBooking. Add one more CPT as booking instance
<?php
// Replace additional-props with your CPT slug
DEFINE( 'BOOKING_ADDITIONAL_CPT', 'additional-props' );
add_filter( 'jet-booking/settings/get/apartment_post_type', function ( $post_type ) {
if ( is_admin() ) {
if ( ! empty( $_GET['post_type'] ) && BOOKING_ADDITIONAL_CPT === $_GET['post_type'] ) {
$post_type = BOOKING_ADDITIONAL_CPT;
}
@MjHead
MjHead / jet-booking-inherit-guests-filter-in-form.php
Last active January 17, 2024 14:27
JetBooking. Connect Guests number filter to Guests field in the form.
<?php
/**
* Instructions:
*
* 1. Create a filter for guests number - https://tppr.me/H7Sjzs, https://tppr.me/D5jImO
* 2. In the example below used 'max_guests' query variable for filter, you need replace it with your own.
* You need to do this under 'Replace this with your filter variable' comment
* 3. After this - each time when this filter applied - selected value will be stored, now you need to apply it in form
* 4. Set this value as default for Guessts field in the form - https://tppr.me/vwdRCV.
* 5. For the form keep the query var name from example - _booking_guests_num - here will be stored selected filter value
@MjHead
MjHead / get-realtion-meta.php
Created August 17, 2022 07:59
Get meta data from JetEngine relations from the code
<?php
$rel_id = 111; // Set here your actual Relation ID. You can get it from an address bar on relation settings edit page
$relation = jet_engine()->relations->get_active_relations( $rel_id );
$parent_id = 111; // ID of prequired arent object from relation
$child_id = 111; // ID of prequired arent object from relation
$key = 'meta_key'; // Name/ID of meta field to get
$meta_value = $relation->get_meta( $parent_id, $child_id, $key );
<?php
add_action(
'elementor/element/jet-blog-smart-listing/section_custom_fields/before_section_end',
'jet_custom_meta_callbacks'
);
add_action(
'elementor/element/jet-blog-smart-tiles/section_custom_fields/before_section_end',
'jet_custom_meta_callbacks'
<?php
add_filter( 'jet-engine/listings/macros-list', 'jet_register_custom_macros' );
/**
* Add new macros to default macros list
*
* %business_users% - macros name
*
*/
@MjHead
MjHead / jet-engine-repeater-filter-only-url.php
Last active December 15, 2023 21:49
Jet Engine, Dynamic Repeater: add new filter to allowed repeater filters
<?php
add_filter( 'jet-engine/listings/filters-list', 'jet_add_pdf_link_filter' );
/**
* Add 'get_pdf_link' to allowed filters list
*
* @param array $filters Registered filters
* @return array
*/
@MjHead
MjHead / filter-by-author-and-post-type.php
Created September 26, 2019 10:35
JetSmartFilters. Filter JetEngine listing grid by author and post type.
<?php
/**
* Register new query variables for post type and author
*
* @param array $vars Default query variables array
* @return array
*/
function my_register_filter_query_vars( $vars ) {
array_unshift( $vars, 'post_type', 'author' );
@MjHead
MjHead / form.json
Last active October 25, 2023 10:54
Allow provider to add services for itself. You need to download these files. form.json you need to import with JetFormBuilder. snippet.json - with code snippets plugin
{"post_title":"Apply to service","post_content":"<!-- wp:jet-forms\/hidden-field {\"name\":\"provider_id\"} \/-->\n\n<!-- wp:jet-forms\/select-field {\"field_options_from\":\"posts\",\"field_options_post_type\":\"services\",\"name\":\"service_id\"} \/-->\n\n<!-- wp:jet-forms\/submit-field \/-->","meta_input":{"_gspb_post_css":"","_jf_actions":"[{\"id\":3775,\"settings\":{\"send_email\":{\"subject\":\"New order on website\",\"content\":\"Hi admin!\\n\\nThere are new order on your website.\\n\\nOrder details:\\n- Post ID: %post_id%\"},\"call_hook\":{\"hook_name\":\"apply-to-service\"}},\"type\":\"call_hook\",\"conditions\":[],\"events\":[]}]"}}