• Resolved yamizer

    (@yamizer)


    hello,
    im trying to use this plugin https://wordpress.org/plugins/hide-this/ so i can hide the summary of the product in the content-single-product page from visitors, this is the code im trying to use the shortcode on to hide

    <div class="gbtr_poduct_details_right_col">
    
    				<div class="product_infos summary">
    
    					<?php
    						do_action( 'woocommerce_single_product_summary_single_title' );
    						do_action( 'woocommerce_single_product_summary_single_rating' );
    						do_action( 'woocommerce_single_product_summary_single_price' );
    						do_action( 'woocommerce_single_product_summary_single_excerpt' );
    						if ( (!isset($theretailer_theme_options['catalog_mode'])) || ($theretailer_theme_options['catalog_mode'] == 0) ) {
    							do_action( 'woocommerce_single_product_summary_single_add_to_cart' );
    						}
    						do_action( 'woocommerce_single_product_summary' );
    						do_action( 'woocommerce_single_product_summary_single_meta' );
    						do_action( 'woocommerce_single_product_summary_single_sharing' );
    					?>
    
    				</div><!-- .summary -->
    
    			</div>
    
    			<div class="clr"></div>
    
    		</div>
    
    		<div class="clr"></div>
    
    		<?php
    			//Get the Thumbnail URL
    			$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), false, '' );
    		?>
    
    		<?php if ((!isset($theretailer_theme_options['sharing_on_product_page'])) || ($theretailer_theme_options['sharing_on_product_page'] == "1")) { ?>
    		<div class="gbtr_product_share">
    			<ul>
    				<li><a href="https://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>" target="_blank" class="product_share_facebook"><?php _e('<span>Share</span> on Facebook', 'theretailer'); ?></a></li>
    				<li><a href="//pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php echo $src[0] ?>&description=<?php strip_tags(the_title()); ?>" target="_blank" class="product_share_pinterest"><?php _e('<span>Pin</span> this item', 'theretailer'); ?></a></li>
    				<li><a href="mailto:enteryour@addresshere.com?subject=<?php strip_tags(the_title()); ?>&body=<?php echo strip_tags(apply_filters( 'woocommerce_short_description', $post->post_excerpt )); ?> <?php the_permalink(); ?>" class="product_share_email"><?php _e('<span>Email</span> a friend', 'theretailer'); ?></a></li>
    				<li><a href="https://twitter.com/share?url=<?php the_permalink(); ?>" target="_blank" class="product_share_twitter"><?php _e('<span>Tweet</span> this item', 'theretailer'); ?></a></li>
    			</ul>
    		</div>
    		<?php } ?>
    
    		<div class="clr"></div>
    
    		<div class="">
    
    			<?php
    				/**
    				 * woocommerce_after_single_product_summary hook
    				 *
    				 * @hooked woocommerce_output_product_data_tabs - 10
    				 * @hooked woocommerce_output_related_products - 20
    				 */
    				do_action( 'woocommerce_after_single_product_summary' );
    			?>
    
    		</div>
    
    <?php if ( $product_page_has_sidebar ) : ?>
    
    	</div><!-- .grid_9-->
    	<?php if ( is_active_sidebar( 'widgets_product_listing' ) ) : ?>
    	<div class="grid_3 pull_9 product_page_sidebar">
    		<div class="gbtr_aside_column_left">
    			<?php dynamic_sidebar('widgets_product_listing'); ?>
    		</div>
    	</div>
    	<?php endif; ?>
    
    <?php endif; ?>     
    
    </div><!-- #product-<?php the_ID(); ?> -->
    
    <?php do_action( 'woocommerce_after_single_product' ); ?>

    and ths is the shortcode of the plugin to use
    <?php echo do_shortcode('[hide for="all" exclude="username:admin"][/hide]'); ?>
    i hope somebody code help me

    https://wordpress.org/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Andrés Villarreal

    (@andrezrv)

    Hi yamizer,

    This is not really what the plugin is meant for, but you can actually achieve that by using output buffering and the plugin’s main PHP class inside your code. It should be something like this:

    <?php
    ob_start(); // Start output buffering.
    ?>
    <!-- Your HTML code goes here -->
    <?php
    $html = ob_get_contents(); // Capture contents inside a variable.
    ob_end_clean(); // End and clean buffer.
    
    if ( class_exists( 'Hide_This' ) ) :
        if ( $output = new Hide_This( array( 'for' => 'all', 'exclude' => 'username:admin' ), $html ) ) :
            echo $output;
        else :
            // Do something else.
        endif;
    endif;

    Please let me know if this helps.

    Best,

    Andrés.

    gnowland

    (@gnowland)

    The above code kept throwing a

    Object of class Hide_This could not be converted to string

    error, so I used a similar method from another post you made:

    $content = '<!-- Your HTML code goes here -->';
    
    if ( class_exists( 'Hide_This' ) ) {
    
        // Construct an array with the shortcode arguments.
        $atts = array(
            'for'     => 'all',
            'exclude' => 'administrator,username:xyz'
        );
    
        $hide_this = new Hide_This( $atts, $content );
    
        echo $hide_this->content;
    
    } else {
    
        echo $content;
    
    }

    (note: I’m allowing all administrators as well as a user with username ‘xyz’ to view the content)

    Hope this helps someone else down the road!

    PS: your plugin rocks!

    Plugin Author Andrés Villarreal

    (@andrezrv)

    Yeah, sorry, I should have called the echo for the content property instead of the object. But it’s great to see you could solve it yourself 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how can i hide this part of the theme?’ is closed to new replies.