Created
June 4, 2021 11:57
-
-
Save Spirecool/baacc18c04e3bb57e24fc8645fea4c34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Créer un produit appellé "Shipping Insurance" à 3 dollars, mettez-le en produit caché (visibilité catalogue dans le côté droit) --> | |
<?php | |
add_action('woocommerce_cart_totals_after_shipping', 'wc_shipping_insurance_note_after_cart'); | |
function wc_shipping_insurance_note_after_cart() { | |
global $woocommerce; | |
$product_id = 669; //mettre l'ID de l'assurance livraison | |
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { | |
$_product = $values['data']; | |
if ( $_product->id == $product_id ) | |
$found = true; | |
} | |
// if product not found, add it | |
if ( ! $found ): | |
?> | |
<tr class="shipping"> | |
<th><?php _e( 'Shipping Insurance', 'woocommerce' ); ?></th> | |
<td><a href="<?php echo do_shortcode('[add_to_cart_url id="669"]'); ?>"><?php _e( 'Add shipping insurance (+$3)' ); ?> </a></td> <!--mettre l'ID de l'assurance livraison --> | |
</tr> | |
<?php else: ?> | |
<tr class="shipping"> | |
<th><?php _e( 'Shipping Insurance', 'woocommerce' ); ?></th> | |
<td>$3</td> | |
</tr> | |
<?php endif; | |
} | |
//si on veut que cette assurance soit obligatoire et sélectionnée automatiquement, mettre ce code : | |
function woo_add_cart_fee() { | |
global $woocommerce; | |
$woocommerce->cart->add_fee( __('Shipping Insurance', 'woocommerce'), 3 ); | |
} | |
add_action( 'woocommerce_before_calculate_totals', 'woo_add_cart_fee' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment