Skip to main content
1 of 2
Nick Young
  • 390
  • 2
  • 15

Alright I want to post this here because of the title of your question.

There is a way to change shortcode attributes, but it will also rely on what the developer of the plugin has done. When a plugin is developed with a shortcode there is an option to use the shortcode_atts() function. This happens most of the time I would say but what some people don't know is that there is a way to let this be modified with a filter. In most plugins you will see something like this:

extract( shortcode_atts( array(
                       'name'                  => get_bloginfo( 'title' ),
                       'description'           => '',
    ), $atts ) );

This is fairly common, however there is one more attribute that can be used:

extract( shortcode_atts( array(
                       'name'                  => get_bloginfo( 'title' ),
                       'description'           => '',
    ), $atts, 'shortcode_name' ) );

See the shortcode_name that got added as a parameter? Well what this does is creates a filter in WordPress that can be used by others. The format to add a filter for this now looks like this:

add_filter( 'shortcode_atts_shortcode_name', 'do_something', 10, 3 );

So we can create an actual filter function like this:

    function do_something( $out, $pairs, $atts ) {      
        if( empty( $out['name'] ) ) {
            $out['name'] = 'This will never be empty now';
        }
    
        return $out;
    }
   add_filter( 'shortcode_atts_shortcode_name', 'do_something', 10, 3 );

References:

https://codex.wordpress.org/Function_Reference/shortcode_atts http://hookr.io/4.1.1/filters/shortcode_atts_shortcode/

Ok so I wrote that up in case others get to this page based on your title.

I think that your problem is a bit different - and also WC does not seem to have it setup to allow the filter I explained above.

Looking at their code around where you pointed out it looks like there is an action hook you can hook into: <?php do_action( "woocommerce_shortcode_before_{$loop_name}_loop" ); ?>

If you can figure out what the $loop_name is for your specific case then I image something like this should work (untested):

function change_wc_col() {
    global $woocommerce_loop;
    
    $woocommerce_loop['columns'] = 3; // Or whatever number of columns you want here
}
add_action( 'woocommerce_shortcode_before_{$loop_name}_loop', 'change_wc_col' );

That seems like it would change the columns value that you stated you are looking to change.

Sorry for the wall of text, but I hope this helps set you in the right direction at least.

Nick Young
  • 390
  • 2
  • 15