• Resolved harvis

    (@harvis)


    Hi my settins are :
    code type: php snippet
    auto insertfronted only
    logic condition: show snippet if: page url contain: /checkout
    Only works if i disable logic condition

    the snippet is:

    function agregar_costo_envio_fijo_a_checkout() {
    if ((is_cart() || is_checkout()) && !is_admin()) {
    $costo_envio = 300.00;
    WC()->cart->add_fee(__(‘Costo de Envío’, ‘text-domain’), $costo_envio, true, ”);
    }
    }
    add_action(‘woocommerce_cart_calculate_fees’, ‘agregar_costo_envio_fijo_a_checkout’);

    add_filter(‘woocommerce_cart_item_name’, ‘mostrar_codigo_en_carrito_y_checkout’, 10, 3);
    function mostrar_codigo_en_carrito_y_checkout($item_name, $cart_item, $cart_item_key) {
    $product = $cart_item[‘data’];
    $sku = $product->get_sku();

    if (!empty($sku)) {
        $item_name .= '<br><small class="product-sku">Código: ' . $sku . '</small>';
    }
    
    return $item_name;

    }

    add_action(‘woocommerce_order_item_meta_start’, ‘mostrar_codigo_en_orden_recibida_y_email’, 10, 3);
    function mostrar_codigo_en_orden_recibida_y_email($item_id, $item, $order) {
    $product = $item->get_product();
    $sku = $product->get_sku();

    if (!empty($sku)) {
        echo '<br><small class="product-sku">Código: ' . $sku . '</small>';
    }

    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @harvis,

    For PHP snippets, when using Conditional Logic, we automatically suggest using the “Frontend Conditional Logic” auto-insert location. This makes sure the snippet is loaded later allowing the conditional logic to have access to all the data needed.

    Please try changing the auto-insert location to “Frontend Conditional Logic” instead of “Frontend Only” and let us know if that doesn’t fix it.

    Plugin Author Mircea Sandu

    (@gripgrip)

    One thing to note here is that the checkout-specific code using conditional logic might not work for some parts of the code. If the filters for the cart, for example, are applied in an AJAX call (that happens in a separate thread from the page load) the conditional logic will not be able to identify that as a checkout page request. I recommend splitting up the code in 3 different snippets with the same logic if things don’t work as expected to identify if some code may need to be adjusted.

    Thread Starter harvis

    (@harvis)

    Seems you are right, i splitted the in 3 parts but however i was unsuccesfull trying to fix it, seems the problem is the ajax thing.

    Thread Starter harvis

    (@harvis)

    I find out that i can make it work by making the conditionals logic show is not, the problem is i have to type many is not urls and type of url to make it work 😂so that an odd solution

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @harvis,

    Thank you for the update, the specific functionality of the code makes a difference in how conditional logic can be used.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Conditional logic not working on a php snippet’ is closed to new replies.