Notez que cet article a été écrit il y a plus de 4 ans, mais il n'est pas forcément obsolète.
WooCommerce est un plugin open source wordPress pour le e-commerce. Le plugin est devenu très populaire de part sa simplicité d’installation et de personnalisation, et pour la gratuité de sa version de base. De nombreux plugins peuvent surcharger la couche woocommerce et apporter de nombreuses améliorations et des fonctionnalités supplémentaires, pas toujours gratuit par contre.
Obtenir le prix d’un produit variable à partir de variation_id
1 2 3 4 5 6 7 8 |
$price = get_post_meta($variation_id, '_price', true); // OR $variable_product = wc_get_product($variation_id); $price = $variable_product->get_price(); // $regular_price = $variable_product->get_regular_price(); // $sale_price = $variable_product->get_sale_price(); |
URL de la page mon-compte :
1 |
$url_myaccount = get_permalink( get_option( 'woocommerce_myaccount_page_id' ); |
Désactiver le bouton Stripe Payment Request :
1 2 |
remove_action( 'woocommerce_proceed_to_checkout', array( WC_Stripe_Payment_Request::instance(), 'display_payment_request_button_html' ), 1 ); remove_action( 'woocommerce_proceed_to_checkout', array( WC_Stripe_Payment_Request::instance(), 'display_payment_request_button_separator_html' ), 2 ); |
Synchroniser le nom, le prénom, l’adresse email dans le screen users.php :
Dans un js jQuery, chargé dans le screen :
1 2 3 4 5 6 7 8 9 |
$( 'input#billing_email, input#email' ).on( 'change', function() { $( 'input#billing_email, input#email' ).val( $( this ).val() ); }); $( 'input#billing_first_name, input#first_name' ).on( 'change', function() { $( 'input#billing_first_name, input#first_name' ).val( $( this ).val() ); }); $( 'input#billing_last_name, input#last_name' ).on( 'change', function() { $( 'input#billing_last_name, input#last_name' ).val( $( this ).val() ); }); |
Cacher l’adresse de livraison dans le screen users.php :
1 2 3 4 5 |
add_filter( 'woocommerce_customer_meta_fields', 'xbs_remove_shipping_fields' ); function xbs_remove_shipping_fields( $show_fields ) { unset( $show_fields['shipping'] ); return $show_fields; } |
Ordre des entrées dans la page commande :
1 2 3 4 5 6 7 8 9 10 11 |
add_filter( 'woocommerce_billing_fields', array( $this, 'wc_billing_fields' ) ); /** * Move billing email input at first position */ public function wc_billing_fields( $fields ) { $fields['billing_email']['priority'] = 8; return $fields; } |