Modify some CSS with functions if (function_exists

I have code function php in my parent theme as path my_parent_theme/include/addon/myfile. I have tried using get stylesheet to load the parent function with no succeed. I just dont know how to handle my file to changes some css.

Here is my function in my_parent_theme/include/addon/myfile

add_filter( 'larismanis_style', 'larismanis_wc_cart_popup_style' );
function larismanis_wc_cart_popup_style( $style ) {
    if ( larismanis_get_integration_wc( 'wc_cartpopup_disable' ) ) {
        return $style;
    }
    $style = $style.'.tp-cart-popup .modal-body { padding-bottom:0; }';
    $style = $style.'.tp-cart-popup button.close { background: none; border: none; }';
    $style = $style.'.tp-cart-popup .woocommerce ul.cart_list { margin: 0; }';
    $style = $style.'.tp-cart-popup .woocommerce ul.cart_list li { padding-left: 0; }';
    $style = $style.'.tp-cart-popup .woocommerce ul.cart_list li .remove { display: none; }';
    $style = $style.'.woocommerce ul.products li.product .added_to_cart.wc-forward, .woocommerce form.cart .added_to_cart.wc-forward, .tp-cart-popup-notices .button { display: none !important; }';
    $style = $style.'.tp-cart-popup .woocommerce.widget_shopping_cart .cart_list li { padding: 0 0 1em; }';
    $style = $style.'.tp-cart-popup-notices .woocommerce-error, .tp-cart-popup-notices .woocommerce-info, .tp-cart-popup-notices .woocommerce-message { margin-bottom: 1em; }';
    $style = $style.'.woocommerce a.button.alt.single_add_to_cart_button.loading, .woocommerce button.button.alt.single_add_to_cart_button.loading, .woocommerce input.button.alt.single_add_to_cart_button.loading { padding-right: 3rem; }';
    $style = $style.'.tp-cart-popup-loading { padding: 0 0 1.5rem; } .tp-cart-popup-loading .spinkit-wave{display:block;position:relative;top:50%;left:50%;width:50px;height:40px;margin:0 0 0 -25px;font-size:10px;text-align:center}.spinkit-wave .spinkit-rect{display:block;float:left;width:6px;height:50px;margin:0 2px;background-color:#e91e63;-webkit-animation:spinkit-wave-stretch-delay 1.2s infinite ease-in-out;animation:spinkit-wave-stretch-delay 1.2s infinite ease-in-out}.spinkit-wave .spinkit-rect1{-webkit-animation-delay:-1.2s;animation-delay:-1.2s}.spinkit-wave .spinkit-rect2{-webkit-animation-delay:-1.1s;animation-delay:-1.1s}.spinkit-wave .spinkit-rect3{-webkit-animation-delay:-1s;animation-delay:-1s}.spinkit-wave .spinkit-rect4{-webkit-animation-delay:-.9s;animation-delay:-.9s}.spinkit-wave .spinkit-rect5{-webkit-animation-delay:-.8s;animation-delay:-.8s}@-webkit-keyframes spinkit-wave-stretch-delay{0%,100%,40%{-webkit-transform:scaleY(.5);transform:scaleY(.5)}20%{-webkit-transform:scaleY(1);transform:scaleY(1)}}@keyframes spinkit-wave-stretch-delay{0%,100%,40%{-webkit-transform:scaleY(.5);transform:scaleY(.5)}20%{-webkit-transform:scaleY(1);transform:scaleY(1)}}';
    return $style;
}

How can I do changes some css required on that function with if function_exists()

Any help would be appreciated!

Topic woocommerce-offtopic function-exists child-theme Wordpress

Category Web


function_exists() isn't going to help you here. That needs to be in the parent theme for you to be able to do anything.

The only way you're going to be able to change this from your chid theme is to use remove_filter() to remove it from the parent theme, and then copy it into your child theme and add that version.

So add this to your child theme:

add_action(
    'after_setup_theme',
    function() {
        remove_filter( 'larismanis_style', 'larismanis_wc_cart_popup_style' );
        add_filter( 'larismanis_style', 'child_larismanis_wc_cart_popup_style' );
    }
);

function child_larismanis_wc_cart_popup_style( $style ) {
    if ( larismanis_get_integration_wc( 'wc_cartpopup_disable' ) ) {
        return $style;
    }
    $style = $style.'.tp-cart-popup .modal-body { padding-bottom:0; }';
    $style = $style.'.tp-cart-popup button.close { background: none; border: none; }';
    $style = $style.'.tp-cart-popup .woocommerce ul.cart_list { margin: 0; }';
    $style = $style.'.tp-cart-popup .woocommerce ul.cart_list li { padding-left: 0; }';
    $style = $style.'.tp-cart-popup .woocommerce ul.cart_list li .remove { display: none; }';
    $style = $style.'.woocommerce ul.products li.product .added_to_cart.wc-forward, .woocommerce form.cart .added_to_cart.wc-forward, .tp-cart-popup-notices .button { display: none !important; }';
    $style = $style.'.tp-cart-popup .woocommerce.widget_shopping_cart .cart_list li { padding: 0 0 1em; }';
    $style = $style.'.tp-cart-popup-notices .woocommerce-error, .tp-cart-popup-notices .woocommerce-info, .tp-cart-popup-notices .woocommerce-message { margin-bottom: 1em; }';
    $style = $style.'.woocommerce a.button.alt.single_add_to_cart_button.loading, .woocommerce button.button.alt.single_add_to_cart_button.loading, .woocommerce input.button.alt.single_add_to_cart_button.loading { padding-right: 3rem; }';
    $style = $style.'.tp-cart-popup-loading { padding: 0 0 1.5rem; } .tp-cart-popup-loading .spinkit-wave{display:block;position:relative;top:50%;left:50%;width:50px;height:40px;margin:0 0 0 -25px;font-size:10px;text-align:center}.spinkit-wave .spinkit-rect{display:block;float:left;width:6px;height:50px;margin:0 2px;background-color:#e91e63;-webkit-animation:spinkit-wave-stretch-delay 1.2s infinite ease-in-out;animation:spinkit-wave-stretch-delay 1.2s infinite ease-in-out}.spinkit-wave .spinkit-rect1{-webkit-animation-delay:-1.2s;animation-delay:-1.2s}.spinkit-wave .spinkit-rect2{-webkit-animation-delay:-1.1s;animation-delay:-1.1s}.spinkit-wave .spinkit-rect3{-webkit-animation-delay:-1s;animation-delay:-1s}.spinkit-wave .spinkit-rect4{-webkit-animation-delay:-.9s;animation-delay:-.9s}.spinkit-wave .spinkit-rect5{-webkit-animation-delay:-.8s;animation-delay:-.8s}@-webkit-keyframes spinkit-wave-stretch-delay{0%,100%,40%{-webkit-transform:scaleY(.5);transform:scaleY(.5)}20%{-webkit-transform:scaleY(1);transform:scaleY(1)}}@keyframes spinkit-wave-stretch-delay{0%,100%,40%{-webkit-transform:scaleY(.5);transform:scaleY(.5)}20%{-webkit-transform:scaleY(1);transform:scaleY(1)}}';
    return $style;
}

Now you can edit the child_larismanis_wc_cart_popup_style() function to change the CSS without needing to edit your parent theme.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.