• Resolved visnucarr

    (@visnucarr)


    Hello! I have made a few needed changes to woocommerce backend files and naturally these are overriden in every update, necessiating me to redo them each time. The changes are minimal, but necessary for my website. Is there some method by which I can make the changes permanent and not be overriden on a module update? Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support omarfpg a11n

    (@omarfpg)

    Hi @visnucarr,

    You could consider working with a child theme, or with a plugin like Code Snippets. You can find more details here: https://woocommerce.com/document/customizing-woocommerce-best-practices/.

    Cheers!
    -OP

    Thread Starter visnucarr

    (@visnucarr)

    Hello. I am aware of code snippets or a child theme. But I am needing to directly modify the WooCommerce plugin itself. A child theme does not help with this. Code Snippets may or may not help. In my case I am making direct modifications to some WooCom files. Maybe CodeSnippet plugin can help me save them, but likely has to be custom/rewritten code.

    Hello @visnucarr,

    While it is technically possible to modify the WooCommerce core files directly, it is highly discouraged due to future update issues.

    When WooCommerce is updated, any changes made to the core files will be overwritten and lost.

    A better practice would be to use hooks and filters provided by WooCommerce. These allow you to modify the functionality without touching the core files. If the existing hooks and filters do not meet your needs, you can indeed use a custom code snippet via the Code Snippets plugin or a similar tool.

    If maybe you can share the changes you have in mind, we would be happy to point you in the right direction on how you could achieve those using hooks, filters or custom code snippets.

    Let us know if you have any further questions.

    Thread Starter visnucarr

    (@visnucarr)

    @ckadenge Thank you for your reply. This is what I have been doing manually and hope to be able to do somehow permanently:

    in line 65 of DraftOrders.php (woocommerce/src/Blocks/Domain/Services/DraftOrders.php) I have been changing the “as_schedule_recurring_action” strtotime to not be 24 hours. I want my draft orders to last longer – in this case 1 month. So in the strtotime I set it to “( ‘+1 month’ )”

    This is the whole function (default, unchanged):

    	/**
    * Maybe create cron events.
    */
    protected function maybe_create_cronjobs() {
    if ( function_exists( 'as_next_scheduled_action' ) && false === as_next_scheduled_action( 'woocommerce_cleanup_draft_orders' ) ) {
    as_schedule_recurring_action( strtotime( 'midnight tonight' ), DAY_IN_SECONDS, 'woocommerce_cleanup_draft_orders' );
    }
    }

    And I change the line:

    as_schedule_recurring_action( strtotime( '+1 month' ), DAY_IN_SECONDS, 'woocommerce_cleanup_draft_orders' );

    Of course the DraftOrders.php file is overridden everytime WooCommerce updates leading me having to manually perform this update which is tedious. Any possibility I can stick it in my function.php file of theme or via Code Snippets? Thank you kindly.

    Zee

    (@doublezed2)

    Hello visnucarr,

    Thank you for your reply.

    The code you have shared is modifying the core code of WooCommerce.
    It cannot be done via Code Snippets or a Child theme.

    According to the forum guidelines, we do not provide support for custom-coded solutions.
    Therefore, I suggest you post this question in Woo Community Slack or Woo Community Facebook group.

    Many Woo devs hang out on these platforms.
    Hopefully, you will get more guidance there. 🙂

    Best regards.

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

The topic ‘Method to save custom changes to WooCom code/templates?’ is closed to new replies.