Home Forums Space themes support forum Custom Query loop coding

Custom Query loop coding

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #626033

    patrik.varga
    Participant

    Hi 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 statuses

    Thanks you helping and best wishes for holidays!

    Patrik

    #626041

    patrik.varga
    Participant

    I 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;
    }

    #626096

    Luke Nielsen
    Keymaster

    Hello,

    Your snippet doesn’t work because there is no such filter as xts_get_products_element_config, you can copy the xts_products_template function in the function.php file in your child theme and make changes there.

    Kind Regards

Viewing 3 posts - 1 through 3 (of 3 total)