Giter Club home page Giter Club logo

Comments (11)

jonas-hoebenreich avatar jonas-hoebenreich commented on June 18, 2024

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.

procontentxyz avatar procontentxyz commented on June 18, 2024

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.

jonas-hoebenreich avatar jonas-hoebenreich commented on June 18, 2024

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.

jonas-hoebenreich avatar jonas-hoebenreich commented on June 18, 2024

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.

procontentxyz avatar procontentxyz commented on June 18, 2024

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.

jonas-hoebenreich avatar jonas-hoebenreich commented on June 18, 2024
$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.

procontentxyz avatar procontentxyz commented on June 18, 2024

$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.

jonas-hoebenreich avatar jonas-hoebenreich commented on June 18, 2024

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.

procontentxyz avatar procontentxyz commented on June 18, 2024

could you please check on your end:

  1. 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.

jonas-hoebenreich avatar jonas-hoebenreich commented on June 18, 2024

yes it is checked

from wc-donation-platform.

procontentxyz avatar procontentxyz commented on June 18, 2024

i am confused what happened on my side....

:(

from wc-donation-platform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.