Reputation: 28
I have made a Custom Product type for Woo commerce, only problem is getting it to work.
i've added a filter for the Product type and it appears in the Dropdown box, however when i click it , it has no boxes other than the SKU .
Is there a certain location that the file has to go that im missing? As i have currently just lobbed it with the other product type files.
Thanks for any help you may give
Upvotes: 0
Views: 3984
Reputation: 86
After you add the product class, you also have to manipulate the meta-boxes for the General tab on the product setup pages. The Price box is there, it is just initially hidden unless the product type is "simple" or "external"
There are a few ways to do this. One (not recommended) is to edit the html-variation-admin.php file directly and add "show_if_customproduct" to the price group div.
<div class="options_group pricing show_if_simple show_if_external">
becomes this:
<div class="options_group pricing show_if_simple show_if_external show_if_customproduct">
Another (better) is to add some javascript by calling the woocommerce_product_options_general_product_data action:
add_action('woocommerce_product_options_general_product_data','showType');
function showType(){ echo "<script>jQuery('.show_if_simple').addClass('show_if_customproduct');</script>"; }
That will turn all "simple" product boxes on for "customproduct" boxes in the general section.
Or, your action can just echo a new div with new boxes, set the div class to "show_if_customproduct," and copy the initial content from the group price div in the html_variations file.
You'll also likely have to add templates for the pages, at the very least to get an "add to cart" buttom. Look under templates/single-product to get the idea.
Upvotes: 2
Reputation: 15550
First of all you need to create a class for your custom product type. Let say it is CustomProduct
class WC_Product_CustomProduct extends WC_Product{
public function __construct( $product ) {
$this->product_type = 'CustomProduct';
parent::__construct( $product );
}
}
and you will put this class under includes/
folder. After that, you need to activate this product type;
add_filter( 'product_type_selector', 'add_custom_product_type' );
function add_custom_product_type( $types ){
$types[ 'CustomProduct' ] = __( 'Custom Product' );
return $types;
}
Add this to functions.php
Upvotes: 2