xah

product attributes

xah
Jun 11th, 2020 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. // hook woocommerce_single_variation?
  2. add_action( 'woocommerce_single_variation', 'custom_attributes', 10 );
  3.  
  4. function custom_attributes(){global $product;
  5.  
  6. if ( get_post_type( $post ) === 'product' && ! is_a($product, 'WC_Product') ) {
  7.     $product = wc_get_product( get_the_id() ); // Get the WC_Product Object
  8. }
  9.  
  10. $product_attributes = $product->get_attributes(); // Get the product attributes
  11.  
  12. // Raw output
  13. echo '<pre>'; print_r( $product_attributes ); echo '</pre>';}
  14.  
  15. // Get custom product attributes
  16. https://stackoverflow.com/questions/13374883/get-custom-product-attributes-in-woocommerce
Add Comment
Please, Sign In to add comment