Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //
- // Setting Custom Product Type for Yarn and Needles, with appropriate custom fields
- //
- // Register the custom product type after init
- function register_yarn_product_type() {
- class WC_Product_Yarn extends WC_Product_Simple {
- public function __construct( $product ) {
- $this->product_type = 'yarn';
- parent::__construct( $product );
- }
- }
- }
- add_action( 'init', 'register_yarn_product_type' );
- // Register custom product type in "Product Data -" drop down menu
- function add_yarn_product( $types ){
- // Key should be exactly the same as in the class product_type parameter
- $types[ 'yarn' ] = __( 'Yarn' );
- return $types;
- }
- add_filter( 'product_type_selector', 'add_yarn_product' );
- }
- // Show pricing fields for yarn product.
- function yarn_custom_js() {
- if ( 'product' != get_post_type() ) : return; endif;
- ?>
- <script>
- jQuery(document).ready(function () {
- // Check which product type is selected
- var selectedProductType = jQuery('#product-type').val();
- // If it's 'yarn', make sure selected tabs are shown
- if (selectedProductType == 'yarn') {
- jQuery("li.inventory_options.inventory_tab,li.general_options.general_tab,div.options_group.pricing,#general_product_data > div.options_group:not(.show_if_downloadable,.show_if_external)").addClass('show_if_yarn').show();
- }
- });
- </script>
- <?php
- }
- add_action( 'admin_footer', 'yarn_custom_js' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement