PHP Code Snippets/Functions

Use a shortcode to add a custom product attribute.

Insert this code into functions.php function custom_product_attributes_shortcode() { ob_start(); global $product; // Check if we’re on a single product page if ( is_product() ) { echo ‘<div class=”product-specs selected-attributes-info”>’; // Get the product attributes $attributes = $product->get_attributes(); $attribute_count = count( $attributes ); if ( $attribute_count === 0 || $attribute_count <= 2 ) { echo ‘<p>Not […]

PHP Code Snippets/Functions

Customize the product layout with specific attributes.

Insert this code into functions.php remove_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_price’, 10 ); add_action(‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_after_shop_loop_item_title_custom’, 10); function woocommerce_after_shop_loop_item_title_custom() { global $product; $attributes = $product->get_attributes(); $colors = $attributes[“pa_color”]; $weight = $attributes[“pa_fabric-weight”]; $width = $attributes[“pa_fabric-width”]; $attributes = $product->get_attributes(); $attribute_count = count( $attributes ); if( $colors ){ $colorTerms = $colors->get_terms(); $selectedAttributesCount = count( $colorTerms ); echo ‘<div class=”product-attributes”>’; echo ‘<span class=”product-attributes-text” […]