Home › Forums › Space themes support forum › Custom Query loop coding
Custom Query loop coding
- This topic has 2 replies, 2 voices, and was last updated 2 days, 11 hours ago by Luke Nielsen.
-
AuthorPosts
-
December 29, 2024 at 10:07 pm #626033
patrik.vargaParticipantHi Xtemos Team!
Could you help me a minimum starting point about the title? I want to make more query loop option but I cant find any info in documentation about it. Example add more option in products widget’s, Product source.
I tried to make it with claude sonnet or Chatgpt o1, but always add to me only for elementor pro’s product widget what is not working with your own widget.
Examples:
– I made a free shipping shipping class, and I want to only listing products what it has this shipping class
– I made more custom product stock status (like in stock) and I want to listing product via my stock statusesThanks you helping and best wishes for holidays!
Patrik
December 29, 2024 at 11:13 pm #626041
patrik.vargaParticipantI tried to extend it with my own snippet (added to snippet into fluent-snippet plugin) but I cant see this in product source drop-down list.
// Bővítsük a termékforrás opciókat
add_filter( ‘xts_get_products_element_config’, ‘custom_add_shipping_classes_to_widget’ );function custom_add_shipping_classes_to_widget( $config ) {
// Ellenőrizzük, hogy létezik a ‘product_source_options’
if ( isset( $config[‘product_source_options’] ) ) {
// Shipping class opciók hozzáadása
$new_sources = array(
‘extra-szallitas-2990’ => __( ‘Extra Szállítás 2990’, ‘text-domain’ ),
‘extra-szallitas-3990’ => __( ‘Extra Szállítás 3990’, ‘text-domain’ ),
‘extra-szallitas-6000’ => __( ‘Extra Szállítás 6000’, ‘text-domain’ ),
‘ingyen-szallitjuk’ => __( ‘Ingyen Szállítjuk’, ‘text-domain’ ),
‘vidd-magad’ => __( ‘Vidd Magad’, ‘text-domain’ ),
);// Importálás az új források a már meglévő forrásokhoz
$config[‘product_source_options’] += $new_sources;
}return $config;
}// Termékek listázása shipping class alapján
add_filter( ‘xts_products_template’, ‘custom_display_products_by_shipping_class_option’, 10, 1 );function custom_display_products_by_shipping_class_option( $element_args ) {
$shipping_classes = array(
‘extra-szallitas-2990’ => 413,
‘extra-szallitas-3990’ => 2299,
‘extra-szallitas-6000’ => 2300,
‘ingyen-szallitjuk’ => 475,
‘vidd-magad’ => 1131,
);// Ellenőrizzük, hogy shipping class legyen a kiválasztott forrás
if ( isset( $element_args[‘product_source’] ) && array_key_exists( $element_args[‘product_source’], $shipping_classes ) ) {
$shipping_class_id = $shipping_classes[ $element_args[‘product_source’] ];global $wpdb;
$product_ids = $wpdb->get_col( $wpdb->prepare(
“SELECT post_id FROM {$wpdb->prefix}term_relationships tr
INNER JOIN {$wpdb->prefix}term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
INNER JOIN {$wpdb->prefix}terms t ON tt.term_id = t.term_id
WHERE t.term_id = %d AND tt.taxonomy = ‘product_shipping_class'”,
$shipping_class_id
));if ( !empty( $product_ids ) ) {
$element_args[‘post__in’] = array_merge( array( 0 ), $product_ids );
} else {
$element_args[‘post__in’] = array( 0 ); // Nincs találat
}
}return $element_args;
}December 30, 2024 at 10:26 am #626096
Luke NielsenKeymasterHello,
Your snippet doesn’t work because there is no such filter as
xts_get_products_element_config
, you can copy thexts_products_template
function in the function.php file in your child theme and make changes there.Kind Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register