product

Completely hide products from unauthorized users in WooCommerce

感情迁移 提交于 2019-12-04 19:52:55
I'm trying to remove a product/products completely from Users that are not logged in and if user is not specific role (e.g Verified Buyer). I have been able to create a new role called Verified Buyer using the code below; add_role( 'verified_buyer', __( 'Verified Buyer', 'text-domain' ), array( 'read' => true, 'edit_posts' => false, ) ); //This Role is same role capability as the WooCommerce Customer role and i have as well added a checkbox to the WooCommerce Add New Product page using the code below function hide_product_from_unathorised_users() { $args = array( 'id' => '_hide_from

How to Show SKU with product title in Order received page and Email order

你。 提交于 2019-12-04 19:37:21
In functions.php add_action( 'woocommerce_add_order_item_meta', 'custom_add_item_sku', 10, 3 ); function custom_add_item_sku( $item_id, $values, $cart_item_key ) { $item_sku = get_post_meta( $values[ 'product_id' ], '_sku', true ); wc_add_order_item_meta( $item_id, 'SKU', $item_sku , false ); } But its showing SKU value below Product title but i want it like this SKU:123sd - Product Name Update 2018-04-01 - Changing of hook and Improved code. Use woocommerce_order_item_name filter hook instead. I have make some changes in your code: add_filter( 'woocommerce_order_item_name', 'sku_before_order

Get the grouped product link from one of it's childs in woocommerce 3

最后都变了- 提交于 2019-12-04 18:47:00
With woocommerce 2.3 there was post_parent for single products what was the part of grouped product. So it was possible to link them by: function parent_permalink_button() { global $post; if( $post->post_parent != 0 ){ $permalink = get_permalink($post->post_parent); echo '<a class="button" href="'.$permalink.'">Link to Parent</a>'; } } with woocommerce 3.0.0 update situation changed. Actually it is opposite now. Grouped product has its _children. How can I create the link from single product to its grouped? It can be a part of more grouped product so there can be multiple links (but it is not

Pass custom calculated product price to cart in Woocommerce

我是研究僧i 提交于 2019-12-04 18:11:03
I have calculated a custom price within the single product page using jquery and have output it as a totalCost variable. How can I use this value and overwrite or pass it through to the checkout to be able to use this new price as the product price? I would post some code but I really dont have a clue where to start. Examples ive seen just set a global price override in the functions file. Many thanks. First step: You should need to add a custom hidden field, where you will pass your calculated price: // Adding a custom imput hidden field in add to cart form add_action( 'woocommerce_before_add

Adding Extra Add to cart button below product summary in Woocommerce

落爺英雄遲暮 提交于 2019-12-04 17:36:20
In WooCommerce, I am trying to add an extra add to cart button below product summary. I successfully added an extra button following this code which works for single products: add_action( 'woocommerce_single_product_summary', 'custom_button_after_product_summary', 30 ); function custom_button_after_product_summary() { global $product; echo "<a href='".$product->add_to_cart_url()."'>add to cart</a>"; } But if the product is a variation it doesn't work. please suggest as what to do? I have revisited your code a bit, and added a 2nd hooked function for variable products: // For Simple products

Add a drop down to product edit pages in product data “General” settings tab

…衆ロ難τιáo~ 提交于 2019-12-04 17:07:06
I am trying to figure out how to modify the singe product options so the product admin can pick from the drop down list the condition of product, i.e. new/ used. Below is a code that allows product admin to enter the condition of product manually. // Enabling and Displaying Fields in backend add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' ); function woo_add_custom_general_fields() { global $woocommerce, $post; echo '<div class="options_group">'; woocommerce_wp_text_input( array( // Text Field type 'id' => '_Stan', 'label' => __( 'Stan',

How to list all products with total sales?

末鹿安然 提交于 2019-12-04 15:44:19
问题 How to list all products from WooCommerce with total sales? This code is just for 1 product only. It's not work if put an array on $product. <?php $product = "13"; $units_sold = get_post_meta( $product, 'total_sales', true ); echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>'; ?> I want on output, format will be like this: [PRODUCT_NAME] - [TOTAL_SALES] 回答1: Try this code. It'll give you output in 2 format <?php global $wpdb; $results = $wpdb->get_results(

Amazon Product API returns “SignatureDoesNotMatch”

匆匆过客 提交于 2019-12-04 13:32:34
I want to write app for get book covers through ISBN (for charity programme). So I decided to use Amazon product API. I got access key and secret key. I got a code for generate secret key I passed URL but that returns like that <?xml version="1.0"?> <ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2005-10-05/"> <Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. </Message></Error><RequestID>6c60b8b7-8b78

WooCommerce - Get the product description by product_id

回眸只為那壹抹淺笑 提交于 2019-12-04 12:14:01
问题 How can I get the product description or the product object using product ID. $order = new WC_Order($order_id); foreach ($order->get_items() as $item) { $product_description = get_the_product_description($item['product_id']); // is there any method can I use to fetch the product description? } The code above extends class WC_Payment_Gateway Any help would be greatly appreciated. 回答1: $order = new WC_Order($order_id); foreach ($order->get_items() as $item) { $product_description = get_post(

Remove single product tabs and add the related content instead In Woocommerce

 ̄綄美尐妖づ 提交于 2019-12-04 12:07:45
I have a client who wants to pull the information that defaults into tabs on single product pages in WooCommerce into a different location on the page and remove the tabs entirely. There are three default product tabs: product Description, Additional Information and Reviews. Removing the tabs and setting up the Description to display was easy enough to set up in /wp-content/plugins/woocommerce/includes/wc-template-hooks.php : remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 ); function woocommerce_template_product_description() { woocommerce