Create programmatically a product using CRUD methods in Woocommerce 3

You are not accessing the WC_Product_simple instance object from your custom Dropship Data Scraper plugin. The guilty can be mostly 2 things: You have not installed Woocommerce. The plugin Dropship Data Scraper is outdated and needs changes, to handle woocommerce. Try to include the global Woocommerce object and to enable Woocommerce support in your plugin. … Read more

Skip Checkout in Magento for a downloadable product

This code will allow logged-in customers to “place an order” for a Free, Virtual product while bypassing checkout and redirect them straight to the My Downloads section of their account. Add the following line to your catalog/product/list.phtml in the spot you want it. <?php if($_product->isVirtual() && $_product->getFinalPrice()==0) { ?> <a href=”https://stackoverflow.com/modulename/checkout/purchase/id/<?php echo $_product->getId()?>”><?php echo $this->__(‘Download … Read more

WooCommerce: Finding the products in database

Update 2020 Products are located mainly in the following tables: wp_posts table with post_type like product (or product_variation), wp_postmeta table with post_id as relational index (the product ID). wp_wc_product_meta_lookup table with product_id as relational index (the post ID) | Allow fast queries on specific product data (since WooCommerce 3.7) wp_wc_order_product_lookuptable with product_id as relational index … Read more

Add a line break in Woocommerce Product Titles

2020 revision – Still works on WordPress 5.5.1 with WooCommerce 4.4.1 Using this custom function hooked in the_title filter hook will do the job (replacing a pipe character | by a <br> in product titles): add_filter( ‘the_title’, ‘custom_product_title’, 10, 2 ); function custom_product_title( $title, $post_id ){ $post_type = get_post_field( ‘post_type’, $post_id, true ); if( in_array( … Read more

Replace add to cart button with a read more linked to product page on shop pages in WooCommerce 3

Replacing the button add to cart by a link to the product in Shop and archives pages for woocommerce 3+: add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘replacing_add_to_cart_button’, 10, 2 ); function replacing_add_to_cart_button( $button, $product ) { $button_text = __(“View product”, “woocommerce”); $button = ‘<a class=”button” href=”‘ . $product->get_permalink() . ‘”>’ . $button_text . ‘</a>’; return $button; } Code goes … Read more

Adding multiple tabs to WooCommerce single product pages

As you are using 4 times the same hook woocommerce_product_tabs, your problem comes from the highest priority on the first one. Instead you should use it only one time, merging that 4 hooked functions in one. Here is your functional tested code, changed a little bit: add_filter( ‘woocommerce_product_tabs’, ‘woo_custom_product_tabs’ ); function woo_custom_product_tabs( $tabs ) { … Read more

Create new product attribute programmatically in Woocommerce

To create a term you can use wp_insert_term() like so: wp_insert_term( ‘red’, ‘pa_colors’ ); where colors is the name of your attribute. The taxonomy name of an attribute is always prepended by pa_. Edit Attributes are merely custom taxonomies. Or you could say they are dynamic taxonomies that are manually created by the user in … Read more

Set product sale price programmatically in WooCommerce 3

The hook woocommerce_get_sale_price is deprecated since WooCommerce 3 and replaced by woocommerce_product_get_sale_price. Also Product displayed prices are cached. When sale price is active, regular price is also active. Try this instead: // Generating dynamically the product “regular price” add_filter( ‘woocommerce_product_get_regular_price’, ‘custom_dynamic_regular_price’, 10, 2 ); add_filter( ‘woocommerce_product_variation_get_regular_price’, ‘custom_dynamic_regular_price’, 10, 2 ); function custom_dynamic_regular_price( $regular_price, $product ) … Read more