Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support WP Lab Support

    (@wp-lab-support)

    Hello Atlasfire.

    I am happy to assist you today.

    Have a look at: wplister_process_template_html You or a developer should be able to take those example code snippets and modify to your needs to create a custom shortcode.

    Kind regards,
    John

    Thread Starter Atlasfire

    (@atlasfire)

    Sorry that link didn’t work? Where can I find the code snippets?

    Kind regards,

    Liz

    Plugin Support WP Lab Support

    (@wp-lab-support)

    Hello atlasfire.

    Sorry about that, forget that link. You can use the following and modify it to your needs. It registers a new custom shortcode that can be used in WPLA profiles. To use it, just enter [product_brands_list] to any of the profile fields and it will be replaced with the brand(s) associated with the product.

    add_action( 'wp_loaded', 'register_product_brands_shortcode' );
    
    function register_product_brands_shortcode() {
        wpla_register_profile_shortcode( 'product_brands_list', 'Product Brands', 'my_product_brands_list' );
        WPLA()->logger->info( 'product_brands_list shortcode registered' );
    }
    function my_product_brands_list( $product_id ) {
        WPLA()->logger->info( 'my_products_brands_list for ID: '. $product_id );
        $brands_tax = wp_get_object_terms( $product_id, 'product_brand', array( 'fields' => 'names' ) );
        WPLA()->logger->info( 'Found brands: '. print_r( $brands_tax, true ) );
        if ( ! is_wp_error( $brands_tax ) ) {
            return implode( ', ', $brands_tax );
        }
    
        WPLA()->logger->info( 'Error gettings brands: '. $brands_tax->get_error_message() );
    
        return '';
    }

    You will need to customize that based on your taxonomy. You can put the correct taxonomy in this line:
    $brands_tax = wp_get_object_terms( $product_id, 'product_brand', array( 'fields' => 'names' ) );

    Kind regards,
    John

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Taxonomy Shortcode’ is closed to new replies.