I can get the properties by selecting the custom property name in the table row (like "Color", "Size", "Weight", etc.), but I only want to display 3 rows. My working code is as follows but it shows all the code and I want to show only 3 lines
add_action( 'cw_shop_page_attribute', 'cw_shop_page_attribute', 25 ); function cw_shop_page_attribute() { global $product; $display_size = $product->get_attribute('display-size'); $processor = $product->get_attribute('processor-type'); $rearcamera = $product->get_attribute('primary-camera'); $frontcamera = $product->get_attribute('secondary-camera'); $storage = $product->get_attribute('internal-storage-gb'); $m_ram = $product->get_attribute('ram-gb'); $frontcamera = $product->get_attribute('secondary-camera'); if ( $display_size ) { echo'<tr class="_plspcdt"><td class="_plspcicon"><i class="fa fa-desktop fa-2x"></i></td><td class="_atrbttl">Display</td>'; echo'<td class="_atrbvlu">'; printf ($display_size); echo'</td></tr>'; } if ( $processor ) { echo'<tr class="_plspcdt"><td class="_plspcicon"><i class="fa fa-microchip fa-2x"></i></td><td class="_atrbttl">Processor</td>'; echo'<td class="_atrbvlu">'; printf ($processor); echo'</td></tr>'; } if ( $rearcamera ) { echo'<tr class="_plspcdt"><td class="_plspcicon"><i class="fa fa-camera fa-2x"></i></td><td class="_atrbttl">Rear Camera</td>'; echo'<td class="_atrbvlu">'; printf ($rearcamera); echo'</td></tr>'; } if ( $frontcamera ) { echo'<tr class="_plspcdt"><td class="_plspcicon"><i class="fa fa-camera fa-2x"></i></td><td class="_atrbttl">Front Camera</td>'; echo'<td class="_atrbvlu">'; printf ($frontcamera); echo'</td></tr>'; }
How to show only 3 rows of them and hide them if they are empty
get_attribute () Returns a comma separated string of values, so you can use php's explode function to loop through the values as an array and then exit after returning 3 results.
For example: