Comments (11)
Hi,
The problem is probably that you are not adding the product appropriately for WooCommerce:
https://wordpress.stackexchange.com/questions/137501/how-to-add-product-in-woocommerce-with-php-code
from wc-donation-platform.
Could you please guide whats wrong with above code OR whats missing.
Because everthing is working right, only product donation become active after hitting publish button manually not with programmatically publish.
Also, am i updating meta for donation correctly??
Please check last two update_meta lines & correct me if i am doing it wrong.
🙏🙏🙏
from wc-donation-platform.
While a product is a custom post type, WooCommerce adds some additional logic using the wc_product_meta_lookup table, such as the product price, whether the product is available, etc. This additional metadata is set as soon as someone manually updates the product.
For example, your code is still missing a price:
update_post_meta( $post_id, '_price', '1' );
I think your link is from a time when the wc_product_meta_lookup table did not exist.
The Donation Platform for WooCommerce specific code looks pretty good to me.
from wc-donation-platform.
Also, I would be grateful if you could post support-related questions in the WordPress support forum in the future: https://wordpress.org/support/plugin/wc-donation-platform/
This will make the questions easier to find for other users.
from wc-donation-platform.
ok i will remember to post on support forum!
only help me last time here on github. please
Here is the new code with latest CRUD method to create product:
,
function create_product(){
// Create an empty instance of the WC_Product
$product = new WC_Product_Simple(); // <=== Simple product
$product->set_name( 'Product Title' );
$product->set_slug( 'product-title' );
$product->set_status( "publish" );
$product->set_virtual( "yes" );
$product->set_regular_price( "1" );
$product->set_catalog_visibility( "visible" );
$product->set_description( "" );
$product->set_short_description( "" );
$product->update_meta_data("_donable", "yes"); <---------------- not working
$product->update_meta_data("wcdp-settings[0]", "1");
$product->update_meta_data("wcdp-settings[1]", "[100,200,500,1000]");
$product->save(); // Save (publish) new product
};
,
everything is now working with only 1 issue, i shown above.
could you tell me why donation product is not selected using any one of above two ?
from wc-donation-platform.
$product = new WC_Product_Simple();
$product->set_name( 'Post Title' );
$product->set_slug( 'slug' );
$product->set_status( "publish" );
$product->set_virtual( "yes" );
$product->set_regular_price( "1" ); //must
$product->set_catalog_visibility( "visible" ); //must
$product->set_description( "" ); // (optional)
$product->set_short_description( "" ); // (optional)
$product->update_meta_data("_donable", "yes");
$product->update_meta_data("wcdp-settings[0]", "1");
$product->update_meta_data("wcdp-settings[1]", "[100,200,500,1000]");
$product->save();
When I run this code with code snippets, it works flawlessly.
What exactly is not working for you?
from wc-donation-platform.
$product->update_meta_data("_donable", "yes");
This is not working, i have to manually set product as donable by checkbox
i also tried this:
$product->set_donable( "yes" );
from wc-donation-platform.
That is weird, when I open the product page in the frontend, everything works fine
Where is the set_donable()
function defined?
from wc-donation-platform.
could you please check on your end:
- Open auto created product & check if donation product checkbox is CHECKED or not ?
i thought like $product->set_virtual( "yes" ); >>>>>>>>>> $product->set_donable( "yes" ); will work.... 🗡️
so silly of me.... hehehe
from wc-donation-platform.
yes it is checked
from wc-donation-platform.
i am confused what happened on my side....
:(
from wc-donation-platform.
Related Issues (20)
- Translating the plugin HOT 10
- Is there a way i can change the "Order" in admin as "Donation" and apply same elsewhere in emails, analytics & reports HOT 1
- Urgent and important suggestion
- Feature request! #2 HOT 1
- Product data tab not working HOT 2
- How to Custom Button popup llink add HOT 1
- Woocommerce update required HOT 2
- translate the plugin HOT 5
- Divi integration causes shutdown HOT 1
- Multi currency support HOT 2
- Fatal error: Uncaught Error: Class "WPO\WC\PDF_Invoices\Compatibility\Order" not found HOT 4
- Progress bar not update HOT 1
- Progress Bar HOT 1
- Shortcodes For Templates HOT 1
- Conflict when using popup style and the dropdown selection. HOT 1
- High-Performance order storage (COT) HOT 1
- Recovery fee issue not showing HOT 2
- Update compatibility for WooCommerce 8.4 and Wordpress 6.4.2 HOT 5
- [BUG] Auto scrolling to start of donation form on page load HOT 1
- [Feature request] automatic scrolling to next step in style 3 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wc-donation-platform.