// reperisce il prezzo non formattato dal custom field assegnandola alla variabile $prezzo $prezzo = get_post_meta( get_the_ID(), '_regular_price', true); // Stampa il prezzo formattato echo wc_price( $prezzo );
Tag: woocommerce
Come reperire i dati di un prodotto utilizzando le funzioni standard di Woocommerce?
// Get $product object from product ID $product = wc_get_product( $product_id ); // Get Product ID $product->get_id(); (fixes the error: "Notice: id was called incorrectly. Product properties should not be accessed directly") // Get Product General Info $product->get_type(); $product->get_name(); $product->get_slug(); $product->get_date_created(); $product->get_date_modified(); $product->get_status(); $product->get_featured(); $product->get_catalog_visibility(); $product->get_description(); $product->get_short_description(); $product->get_sku(); $product->get_menu_order(); $product->get_virtual(); get_permalink( $product->get_id() ); // Get Product Prices $product->get_price(); $product->get_regular_price(); $product->get_sale_price(); $product->get_date_on_sale_from(); $product->get_date_on_sale_to(); $product->get_total_sales(); // Get Product Tax, Shipping & Stock $product->get_tax_status(); $product->get_tax_class(); $product->get_manage_stock(); $product->get_stock_quantity(); $product->get_stock_status(); $product->get_backorders(); $product->get_sold_individually(); $product->get_purchase_note(); $product->get_shipping_class_id(); // Get Product Dimensions $product->get_weight(); $product->get_length(); $product->get_width(); $product->get_height(); $product->get_dimensions(); // Get Linked Products $product->get_upsell_ids(); $product->get_cross_sell_ids(); $product->get_parent_id(); // Get Product Variations $product->get_attributes(); $product->get_default_attributes(); // Get Product Taxonomies $product->get_categories(); $product->get_category_ids(); $product->get_tag_ids(); // Get Product Downloads $product->get_downloads(); $product->get_download_expiry(); $product->get_downloadable(); $product->get_download_limit(); // Get Product Images $product->get_image_id(); $product->get_image(); $product->get_gallery_image_ids(); // Get Product Reviews $product->get_reviews_allowed(); $product->get_rating_counts(); $product->get_average_rating(); $product->get_review_count();
Come reperire i dati di un ordine usando funzioni standard di Woocommerce?
Elendo delle funzione di Woocommerce per reperire i dati di un ordine.
// Get an instance of the WC_Order object (same as before) $order = wc_get_order( $order_id ); // Get Order ID $order->get_id(); // Get Order Totals $0.00 $order->get_formatted_order_total(); $order->get_cart_tax(); $order->get_currency(); $order->get_discount_tax(); $order->get_discount_to_display(); $order->get_discount_total(); $order->get_fees(); $order->get_formatted_line_subtotal(); $order->get_shipping_tax(); $order->get_shipping_total(); $order->get_subtotal(); $order->get_subtotal_to_display(); $order->get_tax_location(); $order->get_tax_totals(); $order->get_taxes(); $order->get_total(); $order->get_total_discount(); $order->get_total_tax(); $order->get_total_refunded(); $order->get_total_tax_refunded(); $order->get_total_shipping_refunded(); $order->get_item_count_refunded(); $order->get_total_qty_refunded(); $order->get_qty_refunded_for_item(); $order->get_total_refunded_for_item(); $order->get_tax_refunded_for_item(); $order->get_total_tax_refunded_by_rate_id(); $order->get_remaining_refund_amount(); // Get Order Items $order->get_items(); $order->get_items_key(); $order->get_items_tax_classes(); $order->get_item(); $order->get_item_count(); $order->get_item_subtotal(); $order->get_item_tax(); $order->get_item_total(); $order->get_downloadable_items(); // Get Order Lines $order->get_line_subtotal(); $order->get_line_tax(); $order->get_line_total(); // Get Order Shipping $order->get_shipping_method(); $order->get_shipping_methods(); $order->get_shipping_to_display(); // Get Order Dates $order->get_date_created(); $order->get_date_modified(); $order->get_date_completed(); $order->get_date_paid(); // Get Order User, Billing & Shipping Addresses $order->get_customer_id(); $order->get_user_id(); $order->get_user(); $order->get_customer_ip_address(); $order->get_customer_user_agent(); $order->get_created_via(); $order->get_customer_note(); $order->get_address_prop(); $order->get_billing_first_name(); $order->get_billing_last_name(); $order->get_billing_company(); $order->get_billing_address_1(); $order->get_billing_address_2(); $order->get_billing_city(); $order->get_billing_state(); $order->get_billing_postcode(); $order->get_billing_country(); $order->get_billing_email(); $order->get_billing_phone(); $order->get_shipping_first_name(); $order->get_shipping_last_name(); $order->get_shipping_company(); $order->get_shipping_address_1(); $order->get_shipping_address_2(); $order->get_shipping_city(); $order->get_shipping_state(); $order->get_shipping_postcode(); $order->get_shipping_country(); $order->get_address(); $order->get_shipping_address_map_url(); $order->get_formatted_billing_full_name(); $order->get_formatted_shipping_full_name(); $order->get_formatted_billing_address(); $order->get_formatted_shipping_address(); // Get Order Payment Details $order->get_payment_method(); $order->get_payment_method_title(); $order->get_transaction_id(); // Get Order URLs $order->get_checkout_payment_url(); $order->get_checkout_order_received_url(); $order->get_cancel_order_url(); $order->get_cancel_order_url_raw(); $order->get_cancel_endpoint(); $order->get_view_order_url(); $order->get_edit_order_url(); // Get Order Status $order->get_status(); // source: https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html
Stampare la categoria prodotto di woocommerce come classe nel body quando visiti un prodotto singolo
Con questa funzione puoi stampare tra le classi del body la categoria del prodotto singolo di woocommerce. Per funzionare basta copiare e incollare la funziona nel file functions.php
function sg_wooc_custom_taxonomy_in_body_class( $classes ){ if( is_singular( 'product' ) ) { $custom_terms = get_the_terms(0, 'product_cat'); if ($custom_terms) { foreach ($custom_terms as $custom_term) { $classes[] = 'term-' . $custom_term->slug; } } } return $classes; } add_filter( 'body_class', 'sg_wooc_custom_taxonomy_in_body_class' );
Stampare la categoria come classe nel body quando visiti un post singolo
Una funzione semplice che aiuta a stampare tra le classi del body la categoria del post singolo. Per funzionare basta copiare e incollare nel file functions.php
function sg_add_category_to_single($classes) { if (is_single() ) { global $post; foreach((get_the_category($post->ID)) as $category) { // add category slug to the $classes array $classes[] = $category->category_nicename; } } // return the $classes array return $classes; } add_filter('body_class','sg_add_category_to_single');
Disattivare Ajax nel Carrello di Woocommerce
Modificare il template file cart.php
form action="" method="post"
Aggiungere in functions.php
//Disattivare ajax nel carrello function cart_script_disabled() { wp_dequeue_script('wc-cart'); } add_action('wp_enqueue_scripts', 'cart_script_disabled');
Nascondere “svuota” dai prodotti variabili su WooCommerce
Per nascondere il link “svuota” dai prodotti variabili che appare sotto il menu a tendina per selezionare la variazione si può usare questo piccolo codice css:
.reset_variations { display: none !important; }
Come si fa a mostrare i prezzi dopo aver fatto Login su Woocommerce?
Incollando questo codice sul file functions.php, il vostro tema non mostrerà più i prezzi dei prodotti invitando i visitatori a loggarsi o registrarsi per poterli vedere. Questa soluzione elimina anche il pulsante aggiungi al carrello.
function woocommerce_show_price_logged($price){ if(is_user_logged_in() ){ return $price; } else { add_action( 'woocommerce_single_product_summary', 'woocommerce_login_to_see_price', 31 ); add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_login_to_see_price', 11 ); remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); } } add_filter('woocommerce_get_price_html', 'woocommerce_show_price_logged'); function woocommerce_login_to_see_price() { echo 'Registrati per vedere i prezzi'; }
Rimuovere il pulsante acquista dalle liste di prodotti su woocommerce
Condivido una funzione php da usare su wordpress che può essere molto utile per chi vuole rimuovere il pulsante “Acquista” da tutte liste di prodotti di woocommerce. La funzione viene usata in combinazione con la action hook “woocommerce_template_loop_add_to_cart” qui descritta e va incollata nel file functions.php perchè funzioni.
function woocommerce_remove_loop_button() { remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10); } add_action('init', 'woocommerce_remove_loop_button');
Controllare se Woocommerce è attivo o no
Qui una piccola funzione molto utile presa dal tema Storefront per controllare se il plugin di Woocommerce è attivo o no.
if ( ! function_exists( 'is_woocommerce_activated' ) ) { function is_woocommerce_activated() { return class_exists( 'woocommerce' ) ? true : false; } }
come usarla
if ( is_woocommerce_activated() ) { echo 'woocomemrce plugin is active :)'; } else { echo 'woocommerce plugin is not active :('; }