File: D:/HostingSpaces/BOoms/pro-oils.be/wwwroot/wp-content/themes/neve-child-master/functions.php
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'neve_child_load_css' ) ):
/**
* Load CSS file.
*/
function neve_child_load_css() {
wp_enqueue_style( 'neve-child-style', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array( 'neve-style' ), NEVE_VERSION );
}
endif;
add_action( 'wp_enqueue_scripts', 'neve_child_load_css', 20 );
// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:
if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
function chld_thm_cfg_locale_css( $uri ){
if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
$uri = get_template_directory_uri() . '/rtl.css';
return $uri;
}
endif;
add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );
if ( !function_exists( 'child_theme_configurator_css' ) ):
function child_theme_configurator_css() {
wp_enqueue_style( 'chld_thm_cfg_separate', trailingslashit( get_stylesheet_directory_uri() ) . 'ctc-style.css', array( 'neve-style','neve-style' ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 20 );
// END ENQUEUE PARENT ACTION
// Custom Function to Include
function my_favicon_link() {
echo '<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />' . "\n";
}
add_action( 'wp_head', 'my_favicon_link' );
// PROEF met Hooks
add_action('pre_get_product_search_form', 'my_favicon_link' );
// PROEF met omschrijvingen
add_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
// TEXT IN WINKELMAND veranderen
function woo_custom_cart_button_text(){
return __( 'IN WINKELMAND', 'woocommerce' );
}
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 +
// END of text veranderen
// Overige verzendmethodes verbergen wanneer "gratis" beschikbaar is
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ){
if ( 'free_shipping' === $rate->method_id ){
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
// Function to change email address
function wpb_sender_email($original_email_address){
if (get_site_url() == "https://pro-oils.be"){
return 'info@pro-oils.be';
}
else{
return 'info@pro-oils.nl';
}
}
// Function to change sender name
function wpb_sender_name($original_email_from){
if (get_site_url() == "https://pro-oils.be"){
return 'Bart';
}
else{
return 'Ton';
}
}
// Hooking up our functions to WordPress filters
add_filter( 'wp_mail_from', 'wpb_sender_email' );
add_filter( 'wp_mail_from_name', 'wpb_sender_name' );
// Menu item om Username in het menu te laten zien
add_filter( 'wp_nav_menu_objects', 'my_custom_menu_item');
function my_custom_menu_item($items) {
$remove_childs_of = array();
foreach($items as $index => $item) {
if($item->title == "##currentuser##") {
if(is_user_logged_in()) {
$user=wp_get_current_user();
$name=$user->display_name; // or user_login , user_firstname, user_lastname
$items[$index]->title = $name;
}
else {
array_push($remove_childs_of, $item->ID);
unset($items[$index]);
}
}
if(!empty($remove_childs_of) && in_array($item->menu_item_parent, $remove_childs_of)) {
array_push($remove_childs_of, $item->ID);
unset($items[$index]);
}
}
return $items;
}
// Veld voor BTW nummer toevoegen aan formulieren
// https://rudrastyh.com/woocommerce/billing-and-shipping-address-fields.html
// https://rudrastyh.com/woocommerce/checkout-fields.html
// https://rudrastyh.com/woocommerce/edit-account-fields.html
add_filter( 'woocommerce_default_address_fields', 'tosc_add_field' );
function tosc_add_field( $fields ) {
$user_id = get_current_user_id();
$user_info = get_userdata( $user_id );
$user_roles = implode(', ', $user_info->roles);
if ($user_roles == "customer") {
$fields['btw_nummer'] = array(
'label' => 'BTW nummer',
'required' => false,
'class' => array( 'form-row-wide', 'my-custom-class' ),
'priority' => 87,
'placeholder' => 'Niet voor particulier',
);
} elseif ($user_roles == "") {
$fields['btw_nummer'] = array(
'label' => 'BTW nummer',
'required' => false,
'class' => array( 'form-row-wide', 'my-custom-class' ),
'priority' => 88,
'placeholder' => 'Ondernemer?',
);
} else {
$fields['btw_nummer'] = array(
'label' => 'BTW nummer',
'required' => true,
'class' => array( 'form-row-wide', 'my-custom-class' ),
'priority' => 89,
'placeholder' => 'NL.. BE..',
);
}
return $fields;
}
// En ook zichtbaar maken in /wp-admin
add_filter( 'woocommerce_customer_meta_fields', 'tosc_admin_address_field' );
function tosc_admin_address_field( $admin_fields ) {
$admin_fields['billing']['fields']['btw_nummer'] = array(
'label' => 'BTW nummer',
'description' => 'BTW nummer van de klant',
);
// or $admin_fields['shipping']['fields']['billing_btw_nummer']
// or both
return $admin_fields;
}
add_filter( 'woocommerce_billing_fields', 'tosc_require_billing_address_2_field');
function tosc_require_billing_address_2_field( $fields ) {
$fields['billing_address_2']['required'] = false;
return $fields;
}
/*
add_filter( 'woocommerce_billing_fields', 'tosc_require_shipping_address_2_field');
function tosc_require_shipping_address_2_field( $fields ) {
$fields['shipping_address_2']['required'] = false;
return $fields;
}
*/
add_filter( 'woocommerce_checkout_fields', 'tosc_remove_fields', 9999 );
function tosc_remove_fields( $woo_checkout_fields_array ) {
// she wanted me to leave these fields in checkout
// unset( $woo_checkout_fields_array['billing']['billing_first_name'] );
// unset( $woo_checkout_fields_array['billing']['billing_last_name'] );
// unset( $woo_checkout_fields_array['billing']['billing_phone'] );
// unset( $woo_checkout_fields_array['billing']['billing_email'] );
// unset( $woo_checkout_fields_array['order']['order_comments'] ); // remove order notes
// unset( $woo_checkout_fields_array['billing']['billing_company'] ); // remove company field
// unset( $woo_checkout_fields_array['billing']['billing_country'] );
// unset( $woo_checkout_fields_array['billing']['billing_address_1'] );
// unset( $woo_checkout_fields_array['billing']['billing_city'] );
// unset( $woo_checkout_fields_array['billing']['billing_state'] ); // remove state field
// unset( $woo_checkout_fields_array['billing']['billing_postcode'] ); // remove zip code field
// and to remove the billing and shipping fields below
unset( $woo_checkout_fields_array['shipping']['shipping_address_2'] );
unset( $woo_checkout_fields_array['billing']['billing_address_2'] );
unset( $woo_checkout_fields_array['shipping']['shipping_btw_nummer'] );
return $woo_checkout_fields_array;
}
add_filter( 'woocommerce_ship_to_different_address_checked', '__return_false' );
/*
// https://stackoverflow.com/questions/37385774/wordpress-get-user-role-with-php
// Elders het volgende gebruiken: <?php echo display_user_roles(); ?>
function display_user_roles(){
$user_id = get_current_user_id();
$user_info = get_userdata( $user_id );
$user_roles = implode(', ', $user_info->roles);
return $user_roles;
}
*/
/**
* @snippet Show Product Inquiry CF7 @ Single Product Page - WooCommerce
* @how-to Get CustomizeWoo.com FREE
* @sourcecode https://businessbloomer.com/?p=21605
* @author Rodolfo Melogli
* @compatible WC 3.5
*/
// --------------------------
// 1. Display Button and Echo CF7
add_action( 'woocommerce_single_product_summary', 'tosc_woocommerce_cf7_single_product', 30 );
function tosc_woocommerce_cf7_single_product() {
$user_id = get_current_user_id();
$user_info = get_userdata( $user_id );
$user_roles = implode(', ', $user_info->roles);
if ($user_roles == "customer") { } elseif ($user_roles == "") { } else {
echo '<button type="submit" id="trigger_cf" class="single_add_to_cart_button button alt">Offerte opvragen</button>';
echo '<div id="product_inq" style="display:none">';
echo do_shortcode('[contact-form-7 id="8560" title="Contact formulier offerte ondernemer"]');
echo '</div>';
}
}
// --------------------------
// 2. Echo Javascript:
// a) on click, display CF7
// b) and populate CF7 subject with Product Name
// c) and change CF7 button to "Sluiten"
add_action( 'woocommerce_single_product_summary', 'tosc_on_click_show_cf7_and_populate', 40 );
function tosc_on_click_show_cf7_and_populate() {
?>
<script type="text/javascript">
jQuery('#trigger_cf').on('click', function(){
if ( jQuery(this).text() == 'Offerte opvragen' ) {
jQuery('#product_inq').css("display","block");
jQuery('input[name="your-subject"]').val('<?php the_title(); ?>');
jQuery("#trigger_cf").html('Sluiten');
} else {
jQuery('#product_inq').hide();
jQuery("#trigger_cf").html('Offerte opvragen');
}
});
</script>
<?php
}
/**
* @snippet Rename "Bestelling Plaatsen" Button @ WooCommerce Checkout ALT
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 3.8
* @donate $0 https://businessbloomer.com/bloomer-armada/
*/
/*
add_filter( 'woocommerce_order_button_html', 'rename_place_order_button_alt', 9999 );
function rename_place_order_button_alt() {
return '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="Bestelling plaatsen" data-value="Bestelling plaatsen">Bestelling plaatsen.</button>';
}
*/
add_action( 'woocommerce_review_order_before_payment', 'tosc_customizing_checkout_button', 10, 0 );
function tosc_customizing_checkout_button(){
$text1 = __( 'Besteling plaatsen.', 'woocommerce' );
$text2 = __( 'Oferte opvragen.', 'woocommerce' );
?>
<script>
console.log("Hiero");
jQuery( document ).ready(function($) {
/*
jQuery(function($){
*/
console.log("Is: " + $('input[name^="payment_method"]:checked').val());
console.log("WCPO: " + $('input[name^="woocommerce_checkout_place_order"]').val());
// 1. Initialising once loaded
if($('input[name^="payment_method"]:checked').val() == 'bacs' )
$('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text2; ?>');
else
$('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text1; ?>');
console.log(">" + $('input[name^="woocommerce_checkout_place_order"]').val());
// 2. Live event detection:When payment method is changed
$( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
var choosenPaymentMethod = $('input[name^="payment_method"]:checked').val(); // Chosen
if( choosenPaymentMethod == 'bacs' )
$('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text2; ?>');
else
$('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text1; ?>');
});
});
</script>
<?php
}
//if (get_site_url() == "https://pro-oils.be") echo
//"Pro Oils Belgium
//Bedrijfsstraat 21
//BE-3500 HASSELT
//T: +32 (0)479 48 49 70
//E: info@pro-oils.be";
//if (get_site_url() != "https://pro-oils.be") echo
//"Pro-Oils Nederland
//Virmundtstraat 14
//NL-5421BW GEMERT
//T: +31 (0)6 13 12 61 82
//E: info@pro-oils.nl";