• Resolved gComm

    (@gcommercepk)


    I want to customize the default shortcode [products skus=””]. Currently the short code only displays product image,name and price. But I want it to display a piece of html with each product after the price. The HTML I want to display is :

    <div class=”btn”> hello </div>

    Please give the the snippit to create a shortcode that can do this. Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    Is there any reason you’d like a button to display without an HREF value? The reason I’m asking is that you could easily add that using the CSS :after or :before selector and then add the content: "Hello"; property ??

    If that’s not going to work for you, you’d need to look into using a hook/filter to add the additional markup to the shortcode. For a full list of hooks/filters that are executed on any given page, you could take a closer look at https://hookr.io/plugin

    Thread Starter gComm

    (@gcommercepk)

    Thanks for the quick reply. Actually i do want to add an href value the final HTML i want to add if this :

    <div class=”button” style=”cursor: pointer;” onclick=”window.location=’/next-page/?{product SKU goes here}’;” class=”sbutton”> HELLO </div>

    As you can see from the HTML above i want to add an href value and then pass a variable into the url which will be the sku of the product being shown. Please can you give me code snippit that i can use the create new short code to achieve this ? Thanks !

    Hi @gcommercepk,

    To echo what RK said, if you need to add detailed information like that, you would need to find a hook that would let you do that. You don’t really want to extend a “shortcode”, but the final code that the shortcode is displaying.

    I would suggest using woocommerce_after_shop_loop_item

    Something like this:

    function marce_after_shop_loop_hook() {
    	echo 'Hello World';
    }
    add_action( 'woocommerce_after_shop_loop_item', 'marce_after_shop_loop_hook' );
    

    Now, if you only want that to happen in certain cases, you can use a conditional tag like this:

    function marce_after_shop_loop_hook() {
    	if ( is_page( '1030' ) ) {
    		echo 'Hello World';
    	}
    }
    add_action( 'woocommerce_after_shop_loop_item', 'marce_after_shop_loop_hook' );
    

    That one would only show on a page with the ID of “1030”.

    See more WordPress Conditional Tags here:
    https://developer.www.ads-software.com/themes/basics/conditional-tags/

    And the WooCommerce Conditional Tags here:
    https://docs.woocommerce.com/document/conditional-tags/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Simple shortcode customization’ is closed to new replies.